Need help with PSOC 5LP SPI code please

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.
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

I am having trouble with SPI routine in my code. This code was ported over from a STM32 to PSOC and is almost running but I am having trouble with the SPI (which is integral to the project). The 5LP connects to a Radio module and sends/receives data and commands via spi.

It first sets spi to low rate to configure a couple of registers and then high rate. I have used DMA to get rid of inter-digit delays.

There is a little routine called "TestSPI()" in main that I call from various points in the code to check the SPI is working correctly. It works perfectly fine and gives expected results until line 100 (A while loop reading status register).

If I call TestSpi before this line it is fine, call it after line 100 and I get rubbish returned in TestSpi.

If I put a 100ms delay after the while statement then I get correct results, but of course I am not able to delay the code here when the application is running.

Thank you

0 Likes
1 Solution
EmHo_296241
Level 5
Level 5
10 solutions authored 50 replies posted 25 replies posted
0 Likes
3 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

What exactly happens in TestSPI API ? I could not find an instance of the function in the attached code ?

Best Regards,
Vasanth

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

The function is in main.c, it simply checks the id, writes and reads some bytes to memory using 32 bit routine and also checks write/read of 16 bit and 8 bit routines

void TestSpi(void){
  dwid = dwt_readdevid();

  uint8 dataA[20] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
  uint8 dataB[20];

  dwt_writetodevice(0x21,0, 20,dataA);
  dwt_readfromdevice(0x21,0,20,dataB);

  dwt_write8bitoffsetreg(0x21, 0x00, dataA[3]);
  dataB[0] =  dwt_read8bitoffsetreg(0x21, 0x00);

  data16 = 0x1234;
  dwt_write16bitoffsetreg(0x21,0x00,data16);
  data16 = dwt_read16bitoffsetreg(0x21,0x00);

  asm("nop");
}

0 Likes
EmHo_296241
Level 5
Level 5
10 solutions authored 50 replies posted 25 replies posted

Hi,

This KBA might be helfpul.

https://www.cypress.com/comment/263266

0 Likes