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

cross mob
gabi_barcan
Level 1
Level 1
5 sign-ins First reply posted First question asked

I am trying to use the SPI (SBC mode) with a PSoC 4 MCU and I have the SPI pins displayed and linked to SPI inputs and SPI outputs. I can toggle the SPI pins but as soon as I linked them to the SPI component I cannot control them at all.

Any ideas what am I missing ?

0 Likes
1 Solution

Hello.

Have a look at PSoC 4 GPIO app notes AN86439.  See section Pin Routing.  There, you'll see how a GPIO output pin has a mux sitting in front of it.  Once SCB has been connected to GPIO thru the mux, you no longer have CPU GPIO write access unless you re-write the HSIOM mux selection.  At least, that's how I understand it.

You could add your own mux to a GPIO output pin where one mux input is from the SCB/SPI output, and the other mux input is from a Control register component that you write to.  To swing this mux, use another Control register component bit to make the selection.  Just something to try.  Of course, when swinging this mux (or the HSIOM mux), you'd have to ensure the SPI transaction has completed first.

View solution in original post

5 Replies
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @gabi_barcan,

Could you please elaborate

  • on linking SPI inputs to SPI outputs and
  • on linking the SPI pins to the SPI component?

Which PSoC 4 device are you using? 

You may refer to the "SCB_SpiCommMaster" and "SCB_SpiCommSlave" code examples in PSoC Creator to better understand using the SPI component. 

[To access code examples, go to File->Code Example-> select the device family and type "SPI" in the filter to get all the code examples related to SPI.]

 

Regards,

Nikhil

 

 

 

0 Likes
gabi_barcan
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hi @ncbs, Thanks a lot for replying, hopefully this is something easy.

I'm using CY8C4248BZI-L489.

When I have the SPI pins connected to GPIO pins like below I CANNOT toggle them between 0 and 1.

gabi_barcan_0-1624930417010.png

The following code does not have any effect on the output pins:

while(true)
{
SPI_SEL_Write(0);
SPI_CLK_Write(0);
SPI_MOSI_Write(0);
CyDelay(100);
SPI_SEL_Write(1);
SPI_CLK_Write(1);
SPI_MOSI_Write(1);
CyDelay(100);
}

All these output pins are defined like this:

gabi_barcan_1-1624930588245.png

If I have them disconnected, meaning no HW connection checked like this:

gabi_barcan_2-1624930729884.png

gabi_barcan_3-1624930760128.png

Then using the same code above I can toggle the output between 0 and 1 without any problems.

Would appreciate any help.

Gabi

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @gabi_barcan,

The functionality of HW connection of a digital output pin dictates how the pin operates.

  • When the HW connection is enabled, then the pin outputs the digital signal supplied by hardware components through the DSI.
  • When the HW connection is disabled, then the output logic level is determined by CPU register or API writes. Since you are using software APIs to control the logic values, HW connection should not be used.

Best regards,
Nikhil

0 Likes

All right, fair enough. I removed the digital pins and just mapped the SPI's pins without having them displayed to the same HW output pins.

So the code looks like this:

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    while(true)
    {
        SPIM_sclk_m_Write(0);
        SPIM_ss0_m_Write(0);
        SPIM_mosi_m_Write(0);
        CyDelay(100);
        SPIM_sclk_m_Write(1);
        SPIM_ss0_m_Write(1);
        SPIM_mosi_m_Write(1);
        CyDelay(100);
    }

 Still the output on the pins is flat, no control. Any ideas why ?

0 Likes

Hello.

Have a look at PSoC 4 GPIO app notes AN86439.  See section Pin Routing.  There, you'll see how a GPIO output pin has a mux sitting in front of it.  Once SCB has been connected to GPIO thru the mux, you no longer have CPU GPIO write access unless you re-write the HSIOM mux selection.  At least, that's how I understand it.

You could add your own mux to a GPIO output pin where one mux input is from the SCB/SPI output, and the other mux input is from a Control register component that you write to.  To swing this mux, use another Control register component bit to make the selection.  Just something to try.  Of course, when swinging this mux (or the HSIOM mux), you'd have to ensure the SPI transaction has completed first.