Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

clarification on the SPI communication

Status
Not open for further replies.

electronicsman

Full Member level 5
Joined
May 4, 2012
Messages
291
Helped
11
Reputation
22
Reaction score
12
Trophy points
1,298
Activity points
3,737
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.
 

Hi,

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

Klaus
 

Ok i will come up with the program in some time. Request to please review that code.
 

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.
 

No it is master mode. Please find the document attached. Page number is 13 and note 3.
 

Attachments

  • spi_70005185a.pdf
    281.1 KB · Views: 104

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.
 

Hi,
Your text doesn't say what data is transmitted...but I assume it's 0x02 again
...yes, it's 0x02...

In my eyes the note just says "SPIxTXB" is a buffer that it keeps it's contents...the same data is transmitted repeatedly if not changed by the user"

Klaus
 

the same data is transmitted repeatedly if not changed by the user
Yes, but it's effectively only possible in slave mode. You can't transmit in master mode without rewriting SPIxBUF.
 

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;   
        
}
 

Attachments

  • program.txt
    5.9 KB · Views: 77


Hi,

Where is your detailed error description?
"Code is not working" tells nothing.

Klaus
 

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?
 

Hi,

Why not simply showing us the analyzer output?

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....

Klaus
 

No it is master mode. Please find the document attached. Page number is 13 and note 3.
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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top