How to receive 32-bit data in SPI slave polling mode?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 6: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.
- Labels:
-
SPI
-
STM32CubeMX
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 7:48 PM
On the STM32, the most common way is to control the CS pins manually (i.e. using HAL_GPIO_WritePin). If you have two CS lines, you need to make sure only one is selected (low) at a time. If that's not happening, could be any number of things wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 6:49 PM
You read 4 bytes, and convert those into the 32 bit value of your choice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 7: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 7: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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 7: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 ​
​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 7:48 PM
On the STM32, the most common way is to control the CS pins manually (i.e. using HAL_GPIO_WritePin). If you have two CS lines, you need to make sure only one is selected (low) at a time. If that's not happening, could be any number of things wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-21 7:57 PM
Thanks! ​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-23 7: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
