Announcements

Equip yourself to optimize PSoc4 MCUs for Evs at the EV Webinar. Click here to register.

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

PSoC™ 4 Forum Discussions

MKocaman
Level 2
Level 2
First solution authored First like received 5 sign-ins

Hello to everyone,
I'm new to PSoC processors. I have the CY8CKIT-041-40XX development kit. I want to run SPI communication. I want to perform this communication in PSoC4 with the LoRa module that I have previously implemented in the STM32 SPL library. But I'm having problems with interrupts. I failed to use the SPI TX empty and RX not empty flags. Without them, I cannot perform SPI_Tx and SPI_Rx operations. If I enable interrupts in the block diagram, I get stuck in the SPI_1_Start() function in the code part, and the code does not progress. If I don't enable interrupts, the code will progress, but I cannot read data in SPI. My code may also be faulty as I am very new to PSoC. I would be very grateful if you could help me with this.

 

1.PNG2.PNG

 

3.PNG

 

4.PNG

 

5.PNG

0 Likes
1 Solution
MKocaman
Level 2
Level 2
First solution authored First like received 5 sign-ins

Hello, I solved my problem. Let me briefly talk about my solution. I noticed that I am sending commands without type conversion in SPI command functions. I think PSOC is a little finicky about it. If the function definition says 32bit, we must send the data we will send in 32 bits with type conversion. This is how I solved my problem.

Thank you to everyone who tried to help. I share working Write and Read functions. Happy New Year to all.

 

1.PNG2.PNG

View solution in original post

8 Replies
Len_CONSULTRON
Level 9
Level 9
500 solutions authored 1000 replies posted 750 replies posted

MKocaman,

You've included much of the schematic and most of the code.  However, there are parts missing.

If you can attach the project, it would be helpful.

Without the entire code, my first impressions on reviewing what you supplied is that is generally not a good idea to place "while()" statements in an interrupt.  This is especially true when executing blocking functions in an interrupt.  (Blocking statements tend to have their own versions of while() inside.

Examples of possible blocking functions are SPI_1_SpiUartReadRxData().

You indicated that you get stuck in SPI_1_Start().   I suspect that in reality, once SPI_1_Start() is initialized and enabled, the interrupt SPI_1_TX_NOT_FULL is true and you launch straight-away into the interrupt associated with SPI_Tx() without exiting SPI_1_Start().  And due to probably waiting for something to come into the port handling SPI_1_SpiUartReadRxData() the interrupt is stuck in the blocking function.

Have you tried running your code with the PSoC Creator debugging tool?

This should indicate exactly where you are "stuck".

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
MKocaman
Level 2
Level 2
First solution authored First like received 5 sign-ins

Firstly, thank you for your reply. I have attached the project. I created and debugged the project in PSoC Creator 4.4. Since I do a lot of projects in the STM32 series, I try to move forward with similar statements at the beginning while learning new processors. PSOC is a processor series that really interests me. I hope I can learn as soon as possible. I would be very grateful if you could help me with this.

0 Likes
MKocaman
Level 2
Level 2
First solution authored First like received 5 sign-ins

To answer your other question, my code gets stuck at the statement shown in the picture. There seems to be a problem with the cuts. When I enable interrupts and tick the interrupts I want, this statement inside the SPI_1_Start() main function gets stuck.

0 Likes

MKocaman,

I downloaded your project.  I retargeted it for a different PSoC4 (CY8C4247LQI-B483) since I don't have a CY8CKIT-041-40XX development kit.

I downloaded the code into it using debug mode.  The code executed all the way to the for(;;) loop in main().

I'm not getting your results.   Additional, you did not post the pictures mentioned above and the ISRs are turned off.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
MKocaman
Level 2
Level 2
First solution authored First like received 5 sign-ins


I updated my code and re-added the project. I noticed that I can follow the TXE and RXNE flags even if I don't enable interrupts in the schematic. There is no need for cutouts for these flags. Since I didn't enable interrupts, my code was executed and is debuggable. But when I try to read data after sending data, I still cannot receive data. The global variable a in the main loop of my code should be 1. Here I check if my code is working correctly. Since I cannot read data from SPI, it cannot return 1 from the relevant function and my variable stays at 0 all the time.

0 Likes
MKocaman
Level 2
Level 2
First solution authored First like received 5 sign-ins

Hello again, I updated my code and re-added the project. I updated my write and read functions. But this time I can only get 0xFF data in reading. Could you please review my code and fix my write and read functions?

0 Likes
MKocaman
Level 2
Level 2
First solution authored First like received 5 sign-ins

Hello, I solved my problem. Let me briefly talk about my solution. I noticed that I am sending commands without type conversion in SPI command functions. I think PSOC is a little finicky about it. If the function definition says 32bit, we must send the data we will send in 32 bits with type conversion. This is how I solved my problem.

Thank you to everyone who tried to help. I share working Write and Read functions. Happy New Year to all.

 

1.PNG2.PNG

MKocaman,

I'm glad you found the reason for the issue.  Thank you for sharing the solution you used.

I recommend that you select "Solved" on your previous post for others who might have a similar issue.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes