2021-05-10 07:43 AM
I make a code that is just send SPI data, and the MISO should not return anything. Here is my code:
int main(void)
{
char user_data[] = "Hello World!";
GPIO_ButtonInit();
SPI2_GPIOInits();
SPI2_Inits();
SPI_SSOEConfig(SPI2,ENABLE);
while(1)
{
while(GPIO_ReadFromInputPin(GPIOC,GPIO_PIN_NO_13));
delay();
SPI_PeripheralControl(SPI2,ENABLE);
uint8_t dataLen = strlen(user_data);
SPI_SendData(SPI2,&dataLen,1);
SPI_SendData(SPI2,(uint8_t*)user_data,strlen(user_data));
while(SPI_GetFlagStatus(SPI2,SPI_BUSY_FLAG));
SPI_PeripheralControl(SPI2,DISABLE);
}
return 0;
}
So, there should be no any SPI receivedata from MISO, but when I look the data at the logic analyzer, the MISO sent back the data from MOSI. It is like echoing, Or Is it because of the SPI nature?
this code I sent "Hello world!" the string length is 12.
First, I send the length of the string to the slave, Then, I send the Hello world! sentence to the slave.
the thing is, every data transmit from the MOSI, there will be a data sent back from MISO which is the sentence of the Hello world!
example in my picture, when I send the length 12, the MISO will exchange the " ! ". which is the last letter of hello world!
Then, when letter H is being sent, the MISO will reply back the length of the string data which is sent previously. Why is this happening? anyone can help me?
2021-05-11 08:19 PM
So, does the copied data from MISO is stored into my master Data register? If yes, do I need to clear it with dummy read in master?
2021-05-11 08:51 PM
I try to send the length of the string only to the master, for the first transmission, the MISO return 0xFF, I where does this value come? is it from the register that has not yet been cleared from MISO?
because after I do second transmission, the MISO return 0x0C which is the string length that I sent before.
To confirm it more, I change the code to send "hello world!" only string to the slave. and what I found is, the first thing that MISO return is the 0x0C data which is the data that I send previously before I change the code. Is this normal for the SPI?