- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I try to communicate with an RFID-Click board with SPI.
For the first touch i decide to use the low level API from Cypress.
Now i´m stuck while i try to read the ID of the Chip.
I hock up a Oscillocop on the SPI bus.
When I watch the Transfer all seems to be okay.
When I plot the Values readed from the rxBuffer I don´t get the expected results.
txBuffer[20]=0;
rxBuffer[20]=0;
void ClearSPIBuffer(){
/* CLear Master status and Tx FIFO status. */ |
Cy_SCB_SPI_ClearSlaveMasterStatus(SPI_1_HW, Cy_SCB_SPI_GetSlaveMasterStatus(SPI_1_HW)); |
Cy_SCB_SPI_ClearTxFifoStatus(SPI_1_HW, CY_SCB_SPI_TX_INTR_MASK ); |
Cy_SCB_SPI_ClearTxFifo(SPI_1_HW); |
/* Clear Rx FIFO status. */ |
Cy_SCB_SPI_ClearRxFifoStatus(SPI_1_HW, CY_SCB_SPI_RX_INTR_MASK); |
Cy_SCB_SPI_ClearRxFifo(SPI_1_HW); |
}
for Write i used:
void SPIWrite(length){
Cy_SCB_SPI_WriteArrayBlocking(SPI_1_HW,txBuffer,length);
while(!Cy_SCB_SPI_IsTxComplete(SPI_1_HW)){
vTaskDelay(0);
}
}
read i try with:
txBuffer[0]=ID_CMD;
SPIWrite(1);
ClearSPIBuffer();
txBuffer[0]=read_CMD;/*reading cmd specify by the RFID Chip*/
txBuffer[1]=0xFF;/*Send Dummy Byte for reading*/
txBuffer[2]=0xFF;
txBuffer[3]=0xFF;
...
txBuffer[16]=0xFF;
txBuffer[17]=0xFF;
SPIWrite(18);
while(Cy_SCB_SPI_GetNumInRxFifo(SPI_1_HW)!=18);
Cy_SCB_SPI_ReadArray(SPI_1_HW,rxBuffer,18);
for(uint8_t i=0;i<18;i++){
printf("recived %u: %u\r\n",i,rxBuffer[0]);
vTaskDeleay(0);
}
On the Oscilliskop i can See the Correct ID but on the Serial Consol i Just get 0x06 what is the resulst from Polling and Echo command what I´m using bevor.
I try to get the correct Code from the SPI_MAST_LOW_LEVEL example.
What do i making wrong to read from an SPI Device?
Is the rxBuffer Updatet by write with Cy_SCB_SPI_WriteArrayBlocking(SPI_1_HW,txBuffer,length) ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Looks like the way you are printing is incorrect.
Please find the attached document which shows the way to print the values in terminal using UART. Can you please implement this in your project and check once?
Thanks
Ganesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
1. Please try the following code sequence to read the ID as mentioned in the code example:
Cy_SCB_SPI_WriteArrayBlocking(mSPI_HW, dummyTxBuf, TX_PACKET_SIZE);
/* Wait until master completes transfer or time out has occured.
If time out occurs handle the error. */
do
{
masterStatus = Cy_SCB_SPI_GetSlaveMasterStatus(mSPI_HW);
Cy_SysLib_Delay(CY_SCB_WAIT_1_UNIT);
timeOut--;
}while ( (masterStatus != (CY_SCB_SPI_MASTER_DONE)) && (timeOut > 0UL) );
/* If masterStatus is CY_SCB_SPI_MASTER_DONE check number of bytes in Rx FIFO and set the status. */
if(masterStatus == CY_SCB_SPI_MASTER_DONE)
{
if(TX_PACKET_SIZE == Cy_SCB_SPI_GetNumInRxFifo(mSPI_HW))
{
/* Read data from Rx FIFO. */
Cy_SCB_SPI_ReadArray(mSPI_HW, statusRxBuf, TX_PACKET_SIZE);
/* Check status packet and set the status flag. */
if((PACKET_SOP == statusRxBuf[RX_PACKET_SOP_POS]) &&
(PACKET_EOP == statusRxBuf[RX_PACKET_EOP_POS]) &&
(STS_CMD_DONE == statusRxBuf[RX_PACKET_STS_POS]) )
{
status = TRANSFER_CMPLT;
}
}
}
else
{
HandleError();
}
ClearSPIBuffer();
2. Please try using High level SPI APIs and see if it is working.
3. "Is the rxBuffer Updatet by write with Cy_SCB_SPI_WriteArrayBlocking(SPI_1_HW,txBuffer,length) ?"
--> Yes. You should have to follow the exact sequence of steps mentioned in the code example.
4. "On the Oscilliskop i can See the Correct ID but on the Serial Consol i Just get 0x06 what is the resulst from Polling and Echo command what I´m using bevor."
--> This is interesting. Please attach the scope images if possible. But before that please follow the above procedure.
Thanks
Ganesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
to 1.
I change the Code like below:
/*======================Start of Code=======================*/
void ClearSPIBuffer(){
/* CLear Master status and Tx FIFO status. */
Cy_SCB_SPI_ClearSlaveMasterStatus(SPI_1_HW, Cy_SCB_SPI_GetSlaveMasterStatus(SPI_1_HW));
Cy_SCB_SPI_ClearTxFifoStatus(SPI_1_HW, CY_SCB_SPI_TX_INTR_MASK );
Cy_SCB_SPI_ClearTxFifo(SPI_1_HW);
/* Clear Rx FIFO status. */
Cy_SCB_SPI_ClearRxFifoStatus(SPI_1_HW, CY_SCB_SPI_RX_INTR_MASK);
Cy_SCB_SPI_ClearRxFifo(SPI_1_HW);
}
void SPIWrite(length){
Cy_SCB_SPI_WriteArrayBlocking(SPI_1_HW,txBuffer,length);
uint32_t masterStatus;
uint32_t timeOut = 1000UL;
do{
masterStatus = Cy_SCB_SPI_GetSlaveMasterStatus(SPI_1_HW);
vTaskDelay(1);
timeOut--;
}while ( (masterStatus != (CY_SCB_SPI_MASTER_DONE)) && (timeOut > 0UL) );
if(masterStatus!=CY_SCB_SPI_MASTER_DONE){
printf("master State is not Done\r\n");
}
}
/*I change from Polling the RFID Chip to receive Interrupt from the Chip*/
ClearWaitForRFID_Interrupt();
/*Write ID cmd to RFID Chip*/
txbuffer[0]=0;
txbuffer[1]=ID_CMD;
txbuffer[2]=0;
SPIWrite(3);
/*Wait until RFID Chip is ready for read*/
waitForRFID_Interrupt();
ClearSPIBuffer();
ClearWaitForRFID_Interrupt();
/*Fill txBuffer with ReadCMD (0x02) and DummyBytes (0xFF)*/
FillTxBuffer();
SPI_Write(18);
/*this transmission is server the correct Response from the RFID-Chip*/
/*proofed with Oscilloscope picture*/
/*How to get this Values on the MISO line inside the RxBuffer?*/
if(Cy_SCB_SPI_GetNumInRxFifo(SPI_1_HW)!=18){
printf("Rx FIFO dont match with sends Value\r\n");
}
/*Wait RFID Chip is ready with transmit*/
waitForRFID_Interrupt();
/*read the Dummy Data from the RxFIFO*/
Cy_SCB_SPI_ReadArray(SPI_1_HW,rxBuffer,18);
print_rxBuffer();
ClearSPIBuffer();
/*======================End of Code=======================*/
But the Change of "waiting for Transmit Finished" don`t change the wrong result.
printfLog:
recived 0: 12
recived 1: 12
recived 2: 12
recived 3: 12
recived 4: 12
recived 5: 12
recived 6: 12
recived 7: 12
recived 8: 12
recived 9: 12
recived 10: 12
recived 11: 12
recived 12: 12
recived 13: 12
recived 14: 12
recived 15: 12
recived 16: 12
recived 17: 12
/*you See no:
* "Rx FIFO dont match with sends Value\r\n"
* "master State is not Done\r\n"
*/
to 3.
Did i not have the exact sequence?
to 4.
On the Oscilloscope i see the correct Values, which i want to read:
0x00 0x0F 0x4E 0x46 0x43 0x20 0x46 ...
Yellow: SPI-CLK
Blue: CS
Red: MOSI
Green: MISO
to 2.
I currently try to get ready with "DMA SPI transmission" but i believed that "low Level transmission" would be a good start to come around with Cypress SPI-Communications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content