My SPI clock produce 16bit rather than 8bit
I have a problem where my SPI clock produce 16bit, where I already set it to 8bit. I am not using any HAL driver, but I am learning from online course to develop my own driver from scratch.
I have a problem at SPI master slave.
The program is like this:
1. nucleo(master) will send 0x50 to arduino(slave)
2. when arduino received the 0x50, It will send back 0xF5 to nucleo.
I check the arduino code, it does transmit the 0xF5, just I dont know why the MISO just echoing back what MOSI has sent.
Example: MOSI sent 0x50, then MISO just send back 0x50. In this case, the master can send the data to the slave, and the slave can receive. Just the slave cannot send data to master.
Why my MISO line reflects back what the MOSI sent? It should send other data. Below is the result from my logic analyzer
Then, below is my SPI send data code:
void SPI_SendData(SPI_RegDef_t *pSPIx, uint8_t *pTxBuffer, uint32_t Len)
{
while(Len > 0)
{
while(SPI_GetFlagStatus(pSPIx, SPI_TXE_FLAG) == FLAG_RESET);
if(pSPIx->CR1 & (1 << SPI_CR1_CRCL))
{
//1. Load the data into Data Register(DR)
pSPIx->DR = *((uint16_t*)pTxBuffer);
//2. decrease len
Len--;
Len--;
//3.increment pTxBuffer in order to make it point to next data item
(uint16_t*)pTxBuffer++;
}
else
{
//8 bit data frame format
//1. Load the data into Data Register(DR)
pSPIx->DR = *pTxBuffer;
//2.kene decrease len
Len--;
//3.increment pTxBuffer in order to make it point to next data item
pTxBuffer++;
}
}
Anyone can help me on this issue?
