新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2021-8-28
- 在线时间
- 2 小时
|
1金钱
spi_clk与lpspiclk有什么区别吗,目前spi的时钟名词有,时钟频率,波特率分频,波特率,怎么理清其中关系
////////////////////////////////////////////////////////////////////////////////
// Step 2: Configure the SPI fynctions
////////////////////////////////////////////////////////////////////////////////
/* Notes:
* 1. Two different clocks configured
* - lpspi_clk : clocks for lpspi function module. Here, we set to 192MHz, or aound 1/5.2ns
* - spi_baudrate: spi_sck frequency, initially to be 4MHz. No more than lpspi_clk/2, and better be lpspi_clk/2^n
* 2. Datasheet says, pcsToSckDelay, lastSckToPcsDelay, betweenTransferDelayInNanoSec should be at least 1cycle of lpspi_clk
*/
u32 lpspi_clk;
u8 lpspi_clk_divid_def = 2; // Default Clock divider = 2, therefore SPI Source Clock =192MHz as default
u32 spi_baudrate = 8000000; //SCK->8MHz Baud=8Mbps. Noted: SCK frequency different from LPSPI Module clock(lpspiclk)
lpspi_master_config_t lpspi_config;
//Setup the SPI Module Clock sources to be PLL3_PFD0/(1+5)=576Mhz/(1+5) = 96MHz
CLOCK_SetMux(kCLOCK_LpspiMux, 1); // Select USB1 PLL PFD0(576MHz) as LPSPI Clock Sources
CLOCK_SetDiv(kCLOCK_LpspiDiv, lpspi_clk_divid_def); // Default Clock divider = 35, therefore SPI Clock = 16MHz Initally
LPSPI_Enable(M8266WIFI_INTERFACE_SPI, false);
lpspi_clk = (CLOCK_GetFreq(kCLOCK_Usb1PllPfd0Clk) / (lpspi_clk_divid_def + 1));
lpspi_config.baudRate = spi_baudrate;
lpspi_config.whichPcs = kLPSPI_Pcs1;
lpspi_config.pcsActiveHighOrLow = kLPSPI_PcsActiveLow;
lpspi_config.bitsPerFrame = 8;
lpspi_config.cpol = kLPSPI_ClockPolarityActiveHigh; // Require Idle Low, so Active High
lpspi_config.cpha = kLPSPI_ClockPhaseFirstEdge; // kLPSPI_ClockPhaseSecondEdge;
lpspi_config.direction = kLPSPI_MsbFirst;
lpspi_config.pinCfg = kLPSPI_SdiInSdoOut;
lpspi_config.dataOutConfig = kLpspiDataOutRetained; // kLpspiDataOutTristate;
lpspi_config.pcsToSckDelayInNanoSec = 5; // The delay is (SCKPCS+1)cycles of lpspi_clk. Therefore, at least 5.02ns @ 192MHz
lpspi_config.lastSckToPcsDelayInNanoSec = 5; // The delay is (PCSSCK+1)cycles of lpspi_clk. Therefore, at least 5.02ns @ 192MHz
lpspi_config.betweenTransferDelayInNanoSec = 10; // The delya is (DBT +2)cycles of lpspi_clk. Therefore, at least 5.02ns @ 192MHz
LPSPI_MasterInit(M8266WIFI_INTERFACE_SPI, &lpspi_config, lpspi_clk);
LPSPI_Enable(M8266WIFI_INTERFACE_SPI, true);
}
|
最佳答案
查看完整内容[请看2#楼]
害,放弃了,spi没有任何问题,淘宝上有一家叫alk的用它家的模块智能他们的家的例程跑起来,移植性非常差,建议没有五六年嵌入式从业经验的友友避坑
|