CH32V103C8T6 SPI 數(shù)據(jù)傳輸問題

測試 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ù)(下圖)有誤:

1668950411174551.jpg

1668950411140774.jpg

發(fā)現(xiàn)在時鐘上升沿(采樣)時數(shù)據(jù)發(fā)生了跳變,圖中紅圈。為什么會出現(xiàn)這個問題??

您好,主機模式會在一字節(jié)最后1bit時,提前輸出下一字節(jié)的第一bit,原因是如果是主機二分頻連續(xù)發(fā)送,就是要實現(xiàn)盡快的發(fā)送出下一bit,這一實現(xiàn)機制沒有區(qū)分分頻比,所以在較大分頻比下,邏輯分析儀粗略看來輸出與采樣邊沿對齊,會造成從機采樣錯誤;但事實上與二分頻情況下相同,主機輸出的數(shù)據(jù)一定會在采樣邊沿后保持一個pclk周期,同時,任何spi從機采樣邏輯一定是在采樣邊沿處進行采樣,所以雖然看起來主機最后1bit輸出保持時間短,實際與從機通信過程中不會有任何問題。附件例程為SPI接收例程,你可以接收測試一下,接收不會有問題,如下圖。

icon_rar.gifCH32V103 SPI接收.zip

image.png




只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频