PSoC 4 SPIM/SPIS (SCB) Example Problems

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.
Anonymous
Not applicable

 I am currently trying to develop software for a PSoC 4 to communicate with a MCP2515 CAN controller; however, I cannot get the SCB SPI block to work. I have a PSoC 4200 Prototyping kit that is programmed via the USB boot loader.

   

 

   

I have copied the blocks, the pin mapping and the code from this example and placed it in the project I created that was bootloadable. I made some small modifications where I replaced the LCD to a uart print out so that I could attempt to do some rudimentary debugging. 

   

The project should simply put a list of SPI commands into the slave tx buffer, then into the master tx buffer, and then should read and print from the opposing rx buffers. This does not work, all I get is 255 for every byte that comes through when they are clearly not meant to be of this value.

   

Further down the track it will be necessary to have this function interrupt driven so I can set masks on the CAN controller and then get messages transmited etc, but I have no implemented this at this stage. 

   

I have attached the example project for your reference. 

   

 

   

Regards,

0 Likes
19 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked
0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Oh no, someone has stolen Bob's keyboard!

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

No, Hli, I'm just spellbound !

   

The *real* story behind this was: I thought I'd find an error in the supplied code and submitted my comment. When I realized that I was wrong it was too late. Since I couldn't delete my post I deleted the text.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

I think we should remove that edit button <grin,duck&run>

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Next time I change the text-color to "white"!

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 Hi Bob,

   

i did your post before it was edited. Your comment was not so much an error in the code as a general code readability comment, correct? The point about the while loop that you mentioned would not cause the code to stop working. 

   

In that regard you did not find any true errors with the code did you? I am having the same problems in that I cannot figure out why there would be a problem when everything looks as it should. To be fair this is my first time using a psoc chip so the intricacies of it are not yet my forte.

   

any help you are able to provide would be much appreciated!

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

How did you determine that its the SCB SPI block thats the culprit? When I understand your description right you send out data via CAN, and the have a second CAN controller (or a loop) and read the transmitted values back.

   

Theres a ton of stuff that could go wrong. So did you check with a scope or logic analyzer that indeed no data is send by the SPI?

   

Are you using the SPI with a software buffer? (Did not look at the schematic, have no Creator at my hands) Then maybe you should enable the global interrupts, otherwise the SPI-internal ISR will not work.

0 Likes
Anonymous
Not applicable

 At the moment I have linked the master and slave Spi pins to each other on the same psoc 4 Proto board. The comment about CAN was to give you some context what what I want to ahcieve at the end. I haven't implemented anything about CAN yet.

   

 

   

I have not put a logic analyser on there yet, or scoped it up. I will scope it up at my next opportunity, but I would guess that there is no signal on any of the pins. If this is the case there must be something wrong with the software i assume. I have checked my pin connections and they are correct.

0 Likes
Anonymous
Not applicable

Well, let's put aside the jokes. Welcome in the forum, lhh. I admitt I haven't seen an error in your project so far, but I know the SPI component does work, no question.  Do you have got (or access to) a logic analyzer that can monitor your connection?

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

My favorite logic analyzer : www.ikalogic.com/ coming from France, so not easy for you to import, but probably you'll find something similar.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 Hi

   

 

   

Thank you for the recommendations. I do not have a logic analyser directly available, I may be able to pull on some contacts in the industry to get my hands on one though. I do have access to a scope, I would assume that if I scoped any of the pins and saw no such signal (pin select) etc then it would not be working.

   

 

   

i have done some recent work also, I have read the length of the Tx and Rx. After putting information into both buffers, the master Rx buffer has a length of 8 and decreases as I read out of it, however all the values are 255. There is nothing in the slave Rx buffer, but the Tx buffer of thenslave has a length of 7. Now that probably adds more confusion.

   

 

   

thanks for the recommendation bob. I am from New Zealand, importing is very easy for use. I will take s look at the recommended analyser. 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The Tx buffer has length 7 because the first byte is already transferred to the transmitter which is not part of the FIFO.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

To make the software TX/RX buffers work, you need to enable global interrupts. Otherwise no data will be transferred from the software buffer to the FIFO (apart from the first byte).

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Search ebay for "saleae logic analyzer", 8 channel for ~ USD 10, a knock off,

   

uses Saleae analyzer software, free download

   

 

   

    

   

          http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2050601.m570.l1311.R4.TR5.TRC2.A0.H0.Xsaleae&_nkw=...

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 I believe I have global interrupts enabled. The cyGlobalIntEnable has been used so I would assume it is working. I don't think I missed this one out, but I may have. 

   

 

   

Thanks for for the link Dana. I will see if I can get one in 3 day shipping as this is a time critical development! 

   

 

   

Thanks once again gain for all the help everyone.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The actual project you provided did not have a CyGlobalIntEnable

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 Hi Bob,

   

You are quite correct, I did not have CyGlobalIntEnable; I have since added this line after starting both SPI SCB blocks.

   

I have created some printouts of what the code is returning when I run it.

   

 

   

Starting up
SPIM TX Buffer Length: 0
SPIM RX Buffer Length: 8
SPIM Read: 255
SPIM RX Buffer Length: 7
SPIM Read: 255
SPIM RX Buffer Length: 6
SPIM Read: 255
SPIM RX Buffer Length: 5
SPIM Read: 255
SPIM RX Buffer Length: 4
SPIM Read: 255
SPIM RX Buffer Length: 3
SPIM Read: 255
SPIM RX Buffer Length: 2
SPIM Read: 255
SPIM RX Buffer Length: 1
SPIM Read: 255
SPIM RX Buffer Length: 0
SPIS TX Buffer Length: 7
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0
SPIS Read: 0
SPIS RX Buffer Length: 0

   
   
        
   
    As you can see the RX buffer for the master is being filled, assumably by the slave device. However, the data inside that is not the data transmitted by the slave. When looking at the slave you can see that indeed the data is still in the TX FIFO and that the master has not transmitted anything to the slave. I have enabled the global interrupt enable and it has not changed the response of the code.   
   
        
   
    I have got an oscilloscope onto the pins also. There is no signal on any of the master lines (Clock, MOSI or SS0). The SS0 remains high the entire time. My oscilloscope is not the greatest (as it is causing the PSoC to be powered through the earth clip on the scope) but it does indicate that nothing is happening on the pins.    
   
        
   
    I am still working on getting a logic analyser, but I would assume if my scope shows nothing, the analyser will also say there is not signal ocurring. It seems like the PSoC is not generating the SPI outputs?   
   
        
   
    Any advice on the next steps to take?   
   
        
   
    Regards,   
   
        
   
    EDIT::    
   
    I have got my hands on a logic analyser (a cheap chinese one). I have hooked it up and selected the channels to the correct outputs (I think). The MOSI and the Enable lines are working (I think) as there is definitely something happening on them. However, there is nothing on the clock line. I am not sure why but there is no clock pulses which is definitely why it is not working. Any suggestions?   
   
        
   
    EDIT2:: Now I can confirm the clock and the enable lines ARE working. Running the example it does indeed produce the number of clock lines and for the correct time period of the enable pin. However; nothing is going out on the MOSI line.    
   
        
   
        
0 Likes
Anonymous
Not applicable

 After doing some further thinking and looking at the pins, I thought could it be related to the fact that MOSI is used in the bootloader as the TX pin? P4_0 and P4_1 are used in the UART bootloader sequence, would it be possible that the use of the bootloader would result in MOSI not being able to work?

0 Likes
Anonymous
Not applicable

I am about to start developing code for a MCP2515 CAN controller connected to a PSoC 4200 (4200BLE in my case). Did you ever resolve this issue? What was the root cause of the issue you were experiencing?

0 Likes