Announcements
IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

DaHu_285096
Contributor II

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
3 Replies
Vasanth
Moderator
Moderator

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
Contributor II

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