SPIM RX Problem

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

This is probably a simple fix and a stupid question, but I am having difficulty try to get the data returned from a PlayStation controller out on the SPIM module.  I am guessing maybe this has to do with the fact that the controller requires delays between bytes?  (Yes I know, normally no delays between bytes, but these things are weird, they require delays between bytes, don't chew me out about it, talk to Sony)

   

I have tried having the array controller_Data[] update from SPIM_ReadRxData() as well as SPIM_rxBuffer[], neither work and when I try to to check controller_Data[] it is filled with 0x00000000.  When i try using SPIM_rxBuffer, it too is always filled with nothing but 0x00000000.  I can see on my oscilloscope correct data being returned from the controller, but the μcontroller does not seem to be recieving them or storing them anywhere.

   

I need those data values so I can do a bit of math with them before sending them to the PWM modules to control servo positions from the joystick positions on the controllers.  Right now I just need to get the data from the controller to the PWM modules is my goal.  Later on I will be doing substantially more math to control a delta bot crane game from the controller, and this will be going to a local kids museum for a robotics exhibit they are doing so the kids can interact with it and use the controller to try and move a ball from a start zone to a goal.

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

    for(i=0;i<3;i++)
    {
        SPIM_WriteTxData(poll_Data);
        controller_Data = SPIM_ReadRxData();
        CyDelayUs(30);
    }

   


This will not quite work as expected:

   

You read the data before it has been received. Check for byte(s) ready using the appropriate APIs.

   

 

   

Bob

View solution in original post

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

    for(i=0;i<3;i++)
    {
        SPIM_WriteTxData(poll_Data);
        controller_Data = SPIM_ReadRxData();
        CyDelayUs(30);
    }

   


This will not quite work as expected:

   

You read the data before it has been received. Check for byte(s) ready using the appropriate APIs.

   

 

   

Bob

0 Likes
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

/* We need to know the moment when SPI communication is complete
    * to display received data. SPIM_SPI_DONE status should be polled. 
    */
    while((SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE) != SPIM_STS_SPI_DONE); 

   

Use in this way the API.

Anonymous
Not applicable

Yes Bob, I realize that isn't correct, I just left it like that as a place holder.  I had been trying proper API's with no luck unfortunately.  I tried what ANKS had suggested earlier to no avail either, but I tried it again, and after reading another community post tried reducing the buffer size from 21 to 4, and it works!  The community post mentioned that if the buffer is set to anything larger then 4 you get a software buffer instead of a hardware buffer if its set to 4 if I understood it correctly.  Not entirely sure why that would cause a problem, but I realize since I am reading a byte after each sent byte that there is no need to have a buffer size of 21.  Main thing is it works and I can get the Delta Bot to the kids museum tomorrow.  Appreciate the help both of you, thank you very much.