Jump to content
Sign in to follow this  
Passah

SPI problem, HELP !!!

Recommended Posts

Hi I have some problem to make my SPI port work on a PIC16F77. PIC should be in master mode with a hard CS on pin RD0.

 

Here is my code:

 

#include

 

//Define device config block

asm

{

list p=PIC16F77

__config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_ON;

}

 

void initSPI(void)

{

 

// Port C

trisc = 0x10;

 

// Port D

trisd = 0x00;

portd = 0x02;

 

// Port A

trisa = 0x00;

 

// Config SSPSTAT

sspstat = 0x00; // SMP = 0, CKE = 0, and clear status bits (BF)

set_bit(sspstat,CKE); // CKE = 1

 

// Config SSPCON

sspcon = 0x31; //Set up SPI port, Master mode, CLK/16,

//Data xmit on falling edge (CKE=1 & CKP=1)

 

// Enable SSP interrupt

clear_bit(pie1,SSPIE);

 

// enable interrupts

disable_interrupt(GIE);

 

}

 

 

 

void writeSPI(void)

{

 

unsigned char rxdata;

 

 

while ((sspstat & 0x01) == 1); // Test si tranmission en cours (BF = 1)

 

// Send data

rxdata = sspbuf; // Clear BF

sspbuf = 0x55;

 

// Send CS

portd = 0x02; // RD_SWITCH = 1, WR_LEDS = 0

portd = 0x03; // RD_SWITCH = 1, WR_LEDS = 1

}

 

 

 

main()

{

initSPI();

 

for(;:D

{

writeSPI();

}

 

}

 

 

Can someone help me plz ?

 

Thx

 

Pascal

Share this post


Link to post
Share on other sites

Hi, I finally have my SPI port working correctly so I give you the code:

 

#include

 

unsigned char rxdata = 0;

 

 

void initSPI(void)

{

 

 // Port C

 portc = 0x00;

 trisc = 0x10;

 

 // Port D

 trisd = 0x00;

 portd = 0x02;

 

 // Port A

 trisa = 0x00;

 

 // Disbale interrupt

 pie1 = 0x00;

 intcon = 0x00;

 

 // Config SSPCON

 //Set up SPI port, Master mode, CLK/16,

 //Data xmit on falling edge (CKE=1 & CKP=1)

 sspcon = 0x32;

}

 

 

void writeSPI(void)

{

 

 unsigned char rxdata;

 

 // Send data

 sspbuf = 0xAA;

 

while ((sspstat & 0x01) == 0); // Test si tranmission terminee (BF = 1)

rxdata = sspbuf;   // Clear BF

 

 

//Send CS

portd = 0x02; // RD_SWITCH = 1, WR_LEDS = 0

portd = 0x03; // RD_SWITCH = 1, WR_LEDS = 1

 

 

}

*/

 

 

 

main()

{

initSPI();

 

for(;:D

{

writeSPI();

}

 

}

Share this post


Link to post
Share on other sites

Hi, I finally have my SPI port working correctly so I give you the code:

 

#include

 

void initSPI(void)

{

 

 // Port C

 portc = 0x00;

 trisc = 0x10;

 

 // Port D

 trisd = 0x00;

 portd = 0x02;

 

 // Port A

 trisa = 0x00;

 

 // Disbale interrupt

 pie1 = 0x00;

 intcon = 0x00;

 

 // Config SSPCON

 //Set up SPI port, Master mode, CLK/16,

 //Data xmit on falling edge (CKE=1 & CKP=1)

 sspcon = 0x32;

}

 

 

void writeSPI(void)

{

 

 unsigned char rxdata;

 

 // Send data

 sspbuf = 0xAA;

 

 // Test if transmission is done (BF = 1)

 while ((sspstat & 0x01) == 0);

 rxdata = sspbuf;   // Clear BF

 

 //Send CS

 portd = 0x02; //   RD_SWITCH = 1, WR_LEDS = 0

 portd = 0x03; //  RD_SWITCH = 1, WR_LEDS = 1

 

}

 

 

main()

{

initSPI();

 

for(;:D

{

writeSPI();

}

 

}

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...