SPI module in PsOc5 not working as expected.

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

cross mob
AlCa_4650741
Level 1
Level 1
First like received

This is my first time working with any psoc device and I am having some problems trying to making the SPI module work.

Here is the piece of code not working:

    SPI_LORA_WriteTxData(outval); 77 where outval = 0x01

    while (SPI_LORA_GetRxBufferSize()<1) ;

    return(SPI_LORA_ReadRxData() );

Using the oscilloscope I was able to test that  "WriteTxData()" is actually writing data in the buffer, but somehow "GetRxBufferSize()" is returning 0 (where it should read '1' at some point, as far as I know), so the while loop does not break.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Although I can not think of a reason why your issue is happening,

I tried the following test with CY8CKIT-059.

I could not observe your problem, so would you test your hardware with similar program?

schematic

003-schematic.JPG

SPIM config

005-SPIM-Config.JPG

006-SPIM-advanced.JPG

pins

004-pins.JPG

main.c

===============

#include "project.h"

#include "stdio.h"

#define STR_LEN 64

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

void cls(void)

{

    print("\033c") ; /* reset */

    CyDelay(20) ;

    print("\033[2J") ; /* clear screen */

    CyDelay(20) ;

}

void splash(void)

{

    cls() ;

    print("5LP SPI Test") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    splash() ;

    SPIM_Start() ;

}

int main(void)

{

    uint8_t outval = 0x01 ;

    uint8_t inval = 0 ;

   

    init_hardware() ;

    for(;;)

    {

        SPIM_WriteTxData(outval) ;

        while(SPIM_GetRxBufferSize() < 1) ;

        inval = SPIM_ReadRxData() ;

        snprintf(str, STR_LEN, "out: 0x%02X  -> in: 0x%02X\n\r", outval, inval) ;

        print(str) ;

        outval++ ;

        inval = 0 ;

        CyDelay(1000) ;

    }

}

===============

Tera Term log

(1) MISO and MOSI were open

Note: I was not expecting the inval has same value with outval.

Probably as I assigned MISO and MOSI to neighbor pins, they may have affected.

000-TeraTerm-Open.JPG

(2) So I connected MISO to GND

Note: inval is alwasy 0x00, which is what I expected.

001-TeraTerm-GND.JPG

(3) Next I connected MISO to VDD

Note: Don't keep this connection for a long time or add some resistor between VDD and the pin.

002-TearTerm-VDD.JPG

moto

View solution in original post

0 Likes
2 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Although I can not think of a reason why your issue is happening,

I tried the following test with CY8CKIT-059.

I could not observe your problem, so would you test your hardware with similar program?

schematic

003-schematic.JPG

SPIM config

005-SPIM-Config.JPG

006-SPIM-advanced.JPG

pins

004-pins.JPG

main.c

===============

#include "project.h"

#include "stdio.h"

#define STR_LEN 64

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

void cls(void)

{

    print("\033c") ; /* reset */

    CyDelay(20) ;

    print("\033[2J") ; /* clear screen */

    CyDelay(20) ;

}

void splash(void)

{

    cls() ;

    print("5LP SPI Test") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    splash() ;

    SPIM_Start() ;

}

int main(void)

{

    uint8_t outval = 0x01 ;

    uint8_t inval = 0 ;

   

    init_hardware() ;

    for(;;)

    {

        SPIM_WriteTxData(outval) ;

        while(SPIM_GetRxBufferSize() < 1) ;

        inval = SPIM_ReadRxData() ;

        snprintf(str, STR_LEN, "out: 0x%02X  -> in: 0x%02X\n\r", outval, inval) ;

        print(str) ;

        outval++ ;

        inval = 0 ;

        CyDelay(1000) ;

    }

}

===============

Tera Term log

(1) MISO and MOSI were open

Note: I was not expecting the inval has same value with outval.

Probably as I assigned MISO and MOSI to neighbor pins, they may have affected.

000-TeraTerm-Open.JPG

(2) So I connected MISO to GND

Note: inval is alwasy 0x00, which is what I expected.

001-TeraTerm-GND.JPG

(3) Next I connected MISO to VDD

Note: Don't keep this connection for a long time or add some resistor between VDD and the pin.

002-TearTerm-VDD.JPG

moto

0 Likes

Hi Moto, it was indeed the Rx and Tx buffer size in the lora module.

Thank you so much.