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.
1 of 1 people found this helpful
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(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. */
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.
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 from CYBLE-014008-EVAL routes to P2 on the CY8CKIT- 042-BLE. Since I connected the SS of my sensor to P0 it didn't work. As soon as I connected SS to P2 and changed the things you proposed in Firmware, it worked...
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.
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
;-) 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.