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.
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;
dummy = SPIM_SpiUartReadRxData();
SPIM_SpiUartWriteTxData(0xFF);//writing Dummy Data
ReadData = SPIM_SpiUartReadRxData(); // Read Data
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..
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.
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