-
1. Re: SPI Master
user_78878863 Mar 23, 2016 3:40 AM (in response to martin.thuering_1536551)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.
-
2. Re: SPI Master
bob.marlowe Mar 23, 2016 4:06 AM (in response to martin.thuering_1536551)1 of 1 people found this helpfulI 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
-
3. Re: SPI Master
martin.thuering_1536551 Mar 24, 2016 6:18 AM (in response to martin.thuering_1536551)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
-
4. Re: SPI Master
bob.marlowe Mar 24, 2016 8:10 AM (in response to martin.thuering_1536551)Awful!
Bob
-
5. Re: SPI Master
martin.thuering_1536551 Mar 31, 2016 11:55 PM (in response to martin.thuering_1536551)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
-
Accelerometer Signal.JPG 122.5 K
-
-
6. Re: SPI Master
bob.marlowe Apr 1, 2016 3:01 AM (in response to martin.thuering_1536551)I changed the buffer size of the SPIM and modified the read-out. UNTESTED
Give it a try.
Bob
-
7. Re: SPI Master
martin.thuering_1536551 Apr 1, 2016 7:21 AM (in response to martin.thuering_1536551)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
-
8. Re: SPI Master
bob.marlowe Apr 1, 2016 7:52 AM (in response to martin.thuering_1536551);-) 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
-
9. Re: SPI Master
venu82450_3009436 Dec 18, 2017 9:27 PM (in response to bob.marlowe)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..
-
10. Re: SPI Master
bob.marlowe Dec 18, 2017 11:57 PM (in response to venu82450_3009436)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
-
11. Re: SPI Master
e.pratt_1639216 Dec 19, 2017 6:41 AM (in response to bob.marlowe)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