Issues with SPI data transfer between Arduino Master and SPI_S module

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi,

   

I've used the SPIS_Example  (Code Example), which saves data using DMA. I've added an interrupt to the DMA_RX (nrq) to notify when the buffer is full and that works fine. When I add an SPI Master module to the slave and transmit the data directly to the SPI slave it works as well.

   

I would like to send data from an arduino sensor to the SPI slave. The SPI Master was removed and the SPI pins added back. I have the slave configured as CPHA=0, CPOL = 0, MSB First, with buffer sizes of 5. The arduino Uno is set up as shown below:

   

void setup() {
  Serial.begin(9600);

   

      pinMode (psoc_ss, OUTPUT);
      digitalWrite(psoc_ss, HIGH);
      delay(1);

   

  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
}

   

and the data is transfered using the following method

   

void notifyPSoC(){

   

Serial.println("Sending floats");

   

digitalWrite(psoc_ss,LOW);

   

float curx = -9.9999;
//transfer float
unsigned char *chptr;
 chptr = (unsigned char *) &curx;
  SPI.transfer(0x11u);
 SPI.transfer(*chptr++);
 SPI.transfer(*chptr++);
 SPI.transfer(*chptr++);
 SPI.transfer(*chptr);
 
 delay(10);
 float cury = -9.9999;
//transfer float
unsigned char *chptr2;
 chptr2 = (unsigned char *) &cury;
 SPI.transfer(*chptr2++);
 SPI.transfer(*chptr2++);
 SPI.transfer(*chptr2++);
 SPI.transfer(*chptr2);

   

 delay(40);
    
 digitalWrite(psoc_ss,HIGH);  

   

}

   

 

   

The issue is the data output from the SPIS module now has no correlation with what is being sent. I have a logic level shifter so that the the arduino can talk to PSoC. Have I missed something obvious?

   

 

   

Thanks

0 Likes
4 Replies
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

Hello ,

   

1)Is it possible for you to probe the MOSI line and check the actual data the Master is sending?

   

2)Have you set the the clock rate properly at the Master's end.

   

In example project the next TD is set as "CY_DMA_DISABLE_TD", this means the TD will be disabled after 10 bytes transfer. Can you check if the SPI master is continuously sending data? In that case you will need to use the TD as Loop.

   

Thanks,

   

Hima

0 Likes
Anonymous
Not applicable

Hi Hima,

   

I haven't set the clock rate at the Masters end. If the Slave has a 2MHZ clock (and the bit rate is 1/2 the input clock frequency) does this mean I need to set the Master's clock to 1MHz? Thanks for pointing out the CY_DMA_DISABLE_TD flag. I have an interrupt when the buffer is full and have been 'disabling' the DMA buffer and then re-enabling it after reading the data. So it has only been working because I have re-enabled the buffer no doubt.Will check the MOSI line, pretty sure it's working, checked the lines much earlier on.

0 Likes
Anonymous
Not applicable

Hi Hima,

   

I have checked the MOSI line and data is being sent. If I change the clock rate it changes the hex data being displayed but it is not the data I expect. If I use the PSoC SPIM module and connect it to the slave it works (the data received is what I expect) so it must be something to do with the arduino (uno) master. I just don't understand..I've spent days on this. Thanks for your help.

0 Likes
Anonymous
Not applicable

I can send a single byte to the slave without issue but the problem is sending multiple bytes. I think it an issue with the RX buffer from the example on the slave (psoc)side. If I want to send two floats should the SPI slave buffer be 8 (8bit words)?  I have an interrupt for the DMA which triggers when the buffer is full. When the flag is cleared I am calling SPIS_ClearRxBuffer() before the channel is enabled. Is this the right way to clear both the DMA buffer and the SPIS buffer?

   

Thanks

0 Likes