SPI Master

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

Hi

   

I am having problems getting data out of a ADXL362 accelerometer.  Here's the datasheet of the ADXL362:

   

http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf

   

I am using CYBLE-01400-800 running on CY8CKIT-042-BLE. Yet I am not dealing with BLE. I am just trying to get the SPI communication between MCU and ADXL362 working. Also, I am using Miniprog3 to program and debug (since on my final prototype, I can only connect Miniprog3). It delivers 2.5 V to the system (which should be fine for both, PSoC MCU and ADXL362)

   

I am using the UDB Version of SPI Master. I read lots of forum posts about PSoC SPI Master and its API's. Most of them included answers from Bob Marlowe and hli (both Cypress employees?). In one forum entrance they mention that it's better to manually control the Slave Select of the SPI. I did this (using a control register) --> using my logic analyzer, I found that the SS line is not going high or low at all (even using the control register). I attached a picture of the logic analyzer output as well. So I guess that's the reason why my ADXL362 does not return any data. However, it might also be that the way I use the SPI Master API is still faulty. Anyway, I attached my project. Please have a look at it and tell me if you see where I am going wrong.

   

Thanks

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

Bob and /me are not Cypress employees. We just happen to have quite some experience with PSoCs, and probably too much time at our hands 🙂

   

Regarding your problem: did you try to trigger at slave select? When you control it manually, there will be a noticeable delay between changing its state and the actual SPI transmission. (apart from checking twice that you actually look at the correct pin...) You can change the default state of the control register output to 1, then you can know that your code handles it correctly.

View solution in original post

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

Bob and /me are not Cypress employees. We just happen to have quite some experience with PSoCs, and probably too much time at our hands 🙂

   

Regarding your problem: did you try to trigger at slave select? When you control it manually, there will be a noticeable delay between changing its state and the actual SPI transmission. (apart from checking twice that you actually look at the correct pin...) You can change the default state of the control register output to 1, then you can know that your code handles it correctly.

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

I can see several small bugs in your code which will prevent the SPI interface from working.

   

uint8 SPIreadOneRegister(uint8 regAddress)
{
    Control_Write(0); //SS low --> Communication between Master and Slave starts
    SPIM_WriteTxData(0x0B);   
    SPIM_WriteTxData(regAddress);
    SPIM_WriteTxData(0x00); /* The master sends a dummy byte and the slave sends back the value that's in the "regAddress" register.*/

   

// At this point you have got 3 bytes in the receive buffer, you need the last byte only

   


    while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE)); /*wait until SPI status = done (SPIM_STS_SPI_DONE flag raised). */
    Control_Write(1);    // should be past the following wait
    while(!(SPIM_GetRxBufferSize())); /*returns 0 = FIFO empty or 1 = FIFO not empty. */
    uint8 rtData = SPIM_ReadRxData();  /*read: Returns the next byte of received data available in the receive buffer. */
    return rtData;
    SPIM_ClearRxBuffer(); //This line will never be executed, leaving bytes in receiver
}

   

SPIM_ClearRxBuffer(); misplaced in function transfer(uint8 data)

   

AccelData readXYZTData() forgot to clear receiver.

   

transfer(uint8 data) forgot to clear reveiver

   

The control register works, but less resources will be used when writing to the pin directly. Configure the pin for no Hardware connection and set the output to initially high to avoid glitches after power-up. Use SS_Write(0) to activate the SS-Line. If in doubt whether the line works correctly, toggle it a few times during initialization and watch with logic analyzer.

   

 

   

Bob

Anonymous
Not applicable

Hi hli and Bob

   

Thank you so much. From your comments I was able to get it running. Also, from this document: http://www.cypress.com/file/157791/download --> p.73 note 19 --> I realized that P0[1] from CYBLE-014008-EVAL routes to P2[0] on the CY8CKIT- 042-BLE. Since I  connected the SS of my sensor to P0[1] it didn't work. As soon as I connected SS to P2[0] and changed the things you proposed in Firmware, it worked...

   

regards

   

Martin

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

Awful!

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Dear Bob and hli

   

So as mentioned my code works. However, every now and then (like every 1000th measurement or so) I get short spikes on my signal. The spikes appear randomly on all 4 signals the accelerometer provides. I don't have a clue where those spikes come from. Do you?

   

I attached a picture of the 4 signals recorded in UC/Probe (Micrium) and also attached the code I am currently using to read my accelerometer.

   

best regards

   

Martin

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I changed the buffer size of the SPIM and modified the read-out. UNTESTED

   

Give it a try.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

You're help is fantastic! I got rid of the spikes, nice smooth signal. Everything working perfectly fine now 🙂

   

I understand how you modified the firmware. I kind of understand why you made the RX/TX buffers 15 bytes each. However, I probably would have made it 8 bytes (or maybe I would have tried with 16 bytes) --> then it would probably not have worked. Can you give a short summary of why you made them 15 bytes?

   

Thanks and best regards

   

Martin

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

😉 Just a generous value greater than your required 6 bytes. Aamof the overhead of the buffer sizes is not more tha just some ram bytes, I could have used 50 bytes unless you are short of sram.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi sir i am interfacing cyble 22001 with Thermocouple ic USING SPI.But while reading data i am getting only 0xff.

my code is here.

uint8  MAX31856_Read_Data(uint8 Reg_Addr)

{

uint8_t ReadData = 0;

    uint8_t dummy = 0;

    SPIM_SpiUartClearRxBuffer();

    SPIM_SpiUartWriteTxData(Reg_Addr);

    while (!SPIM_SpiUartGetRxBufferSize());

    dummy  = SPIM_SpiUartReadRxData();

     SPIM_SpiUartWriteTxData(0xFF);//writing Dummy Data

    while (!SPIM_SpiUartGetRxBufferSize());

    ReadData = SPIM_SpiUartReadRxData(); // Read Data

    return ReadData;

   }

if  i am using this while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE));  compiler unable to find SPIM_ReadTxStatus()  and SPIM_STS_SPI_DONE)

generates error. please help me to solve the issue.Thanks in advance..

0 Likes

Can you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

0 Likes
Anonymous
Not applicable

Based on the data rates and handling etc you could calculate the exact amount of overhead byte-buffering you would need, but unless you really need the extra bytes of RAM, then it is not worth the effort

0 Likes