SPIM API

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
AlVa_264671
Level 5
Level 5
25 sign-ins First like given First like received

Hi there !

   

Can anyone tell me please how send many bytes on spi bus (using the API for SPIM) without  get SS high  before sent all the bytes ?

   

Thank you very much.

0 Likes
9 Replies
Anonymous
Not applicable

 I normally control the cs pin myself via a control register output. 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked
        The SPI-Master has got a FIFO (4 bytes deep). As long as this FIFO is not empty the SS-signal will not go high.   
So you should check the SPIM_ReadTxStatus() for STS_TX_FIFO_NOT_FULL in a loop until you have sent all your bytes to the SPIM. The transfer is handled by the component. When you are using the high-level API SPIM_PutArray() all this will be handled by the internals.   
   
Bob   
0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

This depends on the SPI frequency. When it is too high, even using an interrupt to refill the FIFO is not fast enough. In this case SS will go high even though it should not.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked
        At 1000 kbit/s filling the FIFO with 3 bytes will leave you 24µs to perform that job.   
If that does not work, you may use HI's hint and control a ss-signal yourself.   
   
Bob   
0 Likes
AlVa_264671
Level 5
Level 5
25 sign-ins First like given First like received

Thank you very much Bob and hli for your valuable help.

   

Thanks  both of you , with your suggestion and experience , finaly I could establish comunication with nRFL24L01+.

   

The point was that that chip has a SPI  and requires hold its CSN ( chip select) low over the entire transaccion for send a  write or read comand to set Registers or Verify Register.

   

I 'm using SPIM  API and when I need to send two bytes and receive two ( status register and other one),  there is no issue with the API.

   

The issue  come  up when I am trying to send  a  read  or write comand byte with  5 or more  byte long.  At that time API does not work.

   

I suppose it happend because ss   ( ss( SPIM API) ------->CSN ( nRF24L01+) ),  goes high - low- high,  with every  SPIM_WriteTxData or  SPIM_ReadTxData.

   

I have tried to use void SPIM_PutArray(const uint8/uint16 buffer[], uint8 byteCount) .

   

Taking a look to this fuction, it has a loop with SPIM_WriteTxData, and that implies that ss is getting" low and high too."

   

So, based on both of you suggestion  I have controlled CSN independently of API. I have used a control register for that.

   

And !!!!!! every think work ok so far.

   

So Thank you so much.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Alex, you are always welcome!

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

As said above, when you configure tha SPI buffers to more than 4 bytes (which I assume you did), an internal ISR is used. And it might just not be fast enough to supply the data fast enough before the SPI runs out of data to send. (And if not, a similar thing happens when you send more than 4 bytes with a 4 byte buffer, but then its the API method doing this magic)

0 Likes
Anonymous
Not applicable

Good to here that 

0 Likes
Anonymous
Not applicable

 Gee, folks, I really should have read your posts before I spent a few days figuring this out by myself. I have exactly the same problem. SS goes high before I could put another byte through WriteTxData(). While the slave sees SS going high, it reset itself and call it a day! I am going to use a control register like you guys suggested!

0 Likes