I read the following statement in the datasheet of the SPI family dspic33ev family and it is creating so much confusion. The statement reads like this
If the user application does not change the data in the SPIxBUF register, every new transmission shifts the SPIxBUF register value instead of shifting the value received in the Shift register.
What does it mean? I cannot send a constant value like 0x02 continuously do i need to keep changing or toggling the data? Please help.
I assume (I really don't know)
* there are two hardware (shift) registers sharing the same address (or bus)
* "reading" accesses the receive shift register
* "writing" accesses the transmit shift register
Imagine you want to send out "0x02"
With an SPI transfer "transmit" and "receive" takes place at the same time.
Therefore during "transmit" the receive register is updated, too. (Let's say 0xAA is received)
Reading the shift register contents will give 0xAA, but since there are two physical registers 0xAA is not shifted out as "transmit" data.
Your text doesn't say what data is transmitted...but I assume it's 0x02 again
You should always specify a quoted document unequivocally. I'm unable to locate the statement in Microchip data sheets.
I guess the statement is related to slave mode where transmit is triggered externally, not by writing to SPIxBUF. Only in this case, unintended retransmission can occur.
Are you asking about slave mode? Otherwise the statement is irrelevant.
Thanks. The correct document reference is "dsPIC33/PIC24 Family Reference Manual", section SPI.
The statement is a clarification about the operation of SPIxBUF SFR which actually represents two physical registers. I believe that it doesn't has much relevance in master mode. You are starting a transmission by writing to SPIxBUF, no matter if the data is constant or changing.
Finally I have written the program. Request to please review for mistake, i have made it little bit detailed just in case it is not working and i can make changes to the code and for clarity.
- - - Updated - - -
I think there is a mistake in the code. Will this correct it?
Code:
void TransmitReceiveSpiData(uint16_t *a_tx_data_u16, uint16_t *a_rx_data_u16 )
{
while(!SPI1STATbits.SPITBF); /* Wait till the spi1 txb buffer is empty to load the data */
SPI1BUF = *a_tx_data_u16; /* Load the data into the SPI1 buf to start transmission */
/* immediately start reading the data it is mandatory else overflow will happen */
/* read only when the rxb buffer is filled with data */
while(!SPI1STATbits.SPIRBF);
*a_rx_data_u16 = SPI1BUF;
}
Somehow the code is not working. I am testing with Beagle by total phase bus analyzer https://www.totalphase.com/protocol...IgAipDQPomMQ4y_oiAJfxaAD66_4oYngKJhoC5irw_wcB. I am not sure why it is not working it is sending some invalid data. One clarification i require is dspic33 family works only in DMA mode? Right now i have not enabled DMA mode. Please suggest.
Sorry for not being clear as i really could not understand what data was coming on bus analyzer as the data was constantly changing but i was sending constant data. I changed some settings in the analyzer from mode 0 to mode 1 then it seems to receive the data properly. But in between i am seeing some 2 to 3 error frames not sure why? Do i need to look into it or can i leave it?
Maybe there is one member that can see what is going wrong (or not).
But remember to post ALL necessary informations at once. Code, analyzer output, your description, maybe hardware....
Please be VERY CAREFUL when reading FRM sections that they do actually relate to the SPECIFIC MCU that you are using. As it says in that document (in the note at the tip of Page 2:
Depending on the device variant, this manual section may not apply to all dsPIC33/PIC24 devices.
Therefore it would help f you identify the device you are using completely.
(Having said that, the way that the SPIxBUF register works is pretty much the same across most device variants with that you read NOT being what you wrote, and needing to be very careful when using the debugger or 'watch' capabilities on this register.)
Susan