cancel
Showing results for 
Search instead for 
Did you mean: 

2 STM32F4 Communication using SPI1 ( Urgent )

adarsh
Associate II
Posted on March 18, 2015 at 11:59

The original post was too long to process during our migration. Please click on the attachment to read the original post.
15 REPLIES 15
francescatodiego
Associate II
Posted on March 18, 2015 at 12:29

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6YF&d=%2Fa%2F0X0000000bqW%2FCwvYHHEFNlLeaN6fXvdTEr.frLjFfQZgHO8RPzO.Y_A&asPdf=false
original
Associate II
Posted on March 18, 2015 at 12:50

I suspect that your code does not enter the loop to receive data from Master because of,

if (SPI_I2S_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET)

because RXNE is set to 1 when some data is received => which will be the case when the Master sends some data. Just try setting it to SET and I think it should work. In the case when it compares the flag status to RESET, no data has been received, so it would enter as long as Master sends no data, but this also means that the data received will be 0 => the green LED should be set always. Is that the case?
adarsh
Associate II
Posted on March 18, 2015 at 13:00

Hi Francescato,

Hartley, Thank You for your response,

I have checked with master part which is working fine and the slave itself is not able to get the data in my logic part.

Please if you found any mistakes in my logic and in my slave initialization kindly correct me.

adarsh
Associate II
Posted on March 18, 2015 at 13:06

Hi Kumar,

Thanks for your interest to help me, as you suggested I have made changes from

if (SPI_I2S_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET)

to

if (SPI_I2S_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == SET)

When I have change the condition its not entering into the loop itself, I mean previously the green LED was glowing from the very beginning but at present its not happening too.
Posted on March 18, 2015 at 13:21

As Kumar suggests

if (SPI_I2S_GetFlagStatus(SPI1,  SPI_FLAG_RXNE) != RESET) // Not Reset, there IS some data

{

}

I would probably also only send data when TXE is asserted

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
original
Associate II
Posted on March 18, 2015 at 13:34

Like I said, it would only enter the loop when Master sends something (and hence, it was entering the loop previously and data received was 0x00, so entered the case 0 and stayed there, forever thereafter). If you want it to display the status via LED's, then you can add some code for the 'else' case, i.e, when no data is received, turn the green LED ON (or anything you choose) as an example.

adarsh
Associate II
Posted on March 18, 2015 at 19:15

Hi Kumar,

You are right, receive_data is considering the 0x00 as soon I reset the board and it is entering the case 0, so green LED is continuously glowing all the time.

Even when I press the Master button, it must transmit the value of  i ( using SPI1_send(i); ), now the problem in the slave part where receiving the data from master,   you have suggested me to do some changes, what kind of changes I can do ?? and can you trace why this is not reading the data from register ??

   while(1)

{

if (SPI_I2S_GetFlagStatus(SPI1,  SPI_FLAG_RXNE) == RESET)

{

uint8_t received_data = SPI_I2S_ReceiveData(SPI1);

switch(received_data)

{

Kindly help me ...

Posted on March 18, 2015 at 23:47

if (SPI_I2S_GetFlagStatus(SPI1,  SPI_FLAG_RXNE) == RESET) // << THIS CODE IS WRONG

No, for the third time...

You need to check that the flag is SET, *not* RESET.

Set means there's data available for you to read.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
adarsh
Associate II
Posted on March 19, 2015 at 05:21

Hello Clivel,

How can I test that the flag is SET, *not* RESET ?

Please give me some idea so which helps me a lot