測試 CH32V103C8T6 SPI 數(shù)據(jù)傳輸,代碼如下:
#include "debug.h"
u8 TxData[8] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
void SPI_Initialize(void)
{
??? GPIO_InitTypeDef GPIO_InitStructure = {0};
??? SPI_InitTypeDef? SPI_InitStructure = {0};
??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
??? SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
??? SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
??? SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
??? SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
??? SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
??? SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
??? SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
??? SPI_InitStructure.SPI_CRCPolynomial = 7;
??? SPI_Init(SPI1, &SPI_InitStructure);
??? SPI_Cmd(SPI1, ENABLE);
}
int main(void)
{
??? Delay_Init();
??? SPI_Initialize();
??? Delay_Ms(2000);
??? while(1)
??? {
??????? for (u8 i = 0; i < 8; ++i) {
??????????? while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
??????????? SPI_I2S_SendData(SPI1, TxData[i]);
??????? }
??????? Delay_Ms(500);
??? }
}
抓取到的輸出數(shù)據(jù)(下圖)有誤:
發(fā)現(xiàn)在時鐘上升沿(采樣)時數(shù)據(jù)發(fā)生了跳變,圖中紅圈。為什么會出現(xiàn)這個問題??