2020-03-21 06:09 PM
Hi, I want to receive 32 bit data from a SPI master but in the cubemx options there are only two options available, 8 bits and 16 bits, so what if I want to receive 32 bits frames, what should I do?
Thanks
Solved! Go to Solution.
2020-03-21 07:48 PM
2020-03-21 06:49 PM
You read 4 bytes, and convert those into the 32 bit value of your choice.
2020-03-21 07:09 PM
But how could I read 4 bytes if the cubemx only gives two options for the data size in the slave?, 8 bits and 16 bits
2020-03-21 07:31 PM
You set up the peripheral for 8 bits and send multiple 8-bit transactions. On the bus, these look the same as a 32-bit operation. Are you familiar with the SPI protocol?
For example, if you are trying to send 32 bits:
uint8_t data[4] = {1, 2, 3, 4};
HAL_SPI_Transmit(hspi, data, 4, SPI_TIMEOUT_MAX)
2020-03-21 07:45 PM
I know a little of SPI, so you say that I should do something like this:
1.- CS low
2.- send the data of my 4 bytes buffer
3.- CS high
Is this correct?
And another question, I hope you could help me or maybe I need a new post, I was testing a máster with two slaves, and when I selected the second slave (with the first deselected) the first slave still was able to receive data in its MOSI line, and both CS have pull up resistors, do you know what could de happening?
Thanks
2020-03-21 07:48 PM
2020-03-21 07:57 PM
Thanks!
2020-03-23 07:31 PM
Hi, I have understand that in the master (a ST board) I must select low or high the CS to select the slave (another ST board), but what about the slave?, do I need to implement something like this to receive the data?
//first way
while(1)
{
if (HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1) == 0) //CS pin
{
HAL_SPI_TransmitReceive(&hspi5,txbuffer,rxbuffer, 12, 5000);
}
}
or the function transmitreceive detects internally if the CS is low to start the communication?, I mean, receive the data just doing this:
//second way
while(1)
{
HAL_SPI_TransmitReceive(&hspi5,txbuffer,rxbuffer, 12, 5000);
}
I have this query because I am doing tests (second way) in the slave but always receive data, when I connect the CS pin to GND or 3.3V