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.

[PIC] Help On SPI Implementation

Status
Not open for further replies.

davidmeetsall

Newbie level 2
Joined
Dec 1, 2016
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
37
Hello Friends,

Started learning SPI. Trying 8-bit transfer from PIC (Master ) to a microcontroller(Slave).
MCC code generated and flashed on device. Tried to see the Clock(RC3 pin ), data on SDI(RC4 pin) and SDO(RC5 pin) lines using oscilloscope. FOSC is 16MHZ. Clock rate set as FOSC/4. Able to see clock at RC3 pin but frequency is different shown on oscilloscope. Also not seeing data on SDO and SDI lines. I generated correct MCC code.
When I debug using Real ICE, I can see SSPBF while sent is getting A1, and receiving B9 in the below code. Slave is selected.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
uint8_t SPI_Exchange8bit(uint8_t data)
{
// Clear the Write Collision flag, to allow writing
SSPCON1bits.WCOL = 0;
SSPBUF = data; //Send Data A1
while(SSPSTATbits.BF == SPI_RX_IN_PROGRESS)
{
}
return (SSPBUF); //Received B9
}
void SPI_Initialize(void)
{
// Set the SPI module to the options selected in the User Interface 
// R_nW write_noTX; P stopbit_notdetected; S startbit_notdetected; BF RCinprocess_TXcomplete; SMP Middle; UA dontupdate; CKE Idle to Active; D_nA lastbyte_address; 
SSPSTAT = 0x00; 
// SSPEN enabled; WCOL no_collision; CKP Idle:Low, Active:High; SSPM0 FOSC/4; SSPOV no_overflow; 
SSPCON1 = 0x20; 
// SSPADD 0; 
SSPADD = 0x00;
}



PIN INITIALIZATION, OSCILLATOR INITIALIZATION has been done by MCC.

Let me know why data is not traceable on SDO, SDI, lines.

--David.
 
Last edited by a moderator:

Which PIC ? See if you need to disable ADC funtionality on SPI pins.
 

Be careful when debugging the SSPBUF register as it is not a 'standard' SFR.
What you read is what the SPI peripheral last received - and a second read may or may not return the same value (this behaviour is undefined for (nearly) all of the PIC chips of all families). It is almost certainly not what you would have written into the SSPBUF register - the hardware hides buffer registers and the SPI shift register behind the SSPBUF.
Unfortunately the hardware cannot tell the difference between your program code and the debugger reading the register. It is always safer to check the value before you write it to the SSPBUF register and also transfer the SSPBUF register to some variable location and check it there with the debugger.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top