bigdogguru
Administrator
- Joined
- Mar 12, 2010
- Messages
- 9,821
- Helped
- 2,350
- Reputation
- 4,694
- Reaction score
- 2,272
- Trophy points
- 1,413
- Location
- Southwest, USA
- Activity points
- 62,394
yes a bit clearer now.. I will just use PORTB instead in my future I/O programs...
void SPI_init()
{
/* Enables serial port and configures SCK, SDO, SDI and SS as serial port pins */
SSPCON1 = 0b00100000;
/* Input data sampled at end of data output time
Transmit occurs on transition from active to Idle clock state */
SSPSTAT = 0b11000000;
TRISCbits.TRISC7 = 0; //SD0 set as output
TRISBbits.TRISB0 = 1; //SDI set as input
TRISBbits.TRISB1 = 0; //SCK set as output
TRISCbits.TRISC2 = 0; //CS set as output
}
"When SSPSR
receives a complete byte, it is transferred to SSPBUF
and the SSPIF interrupt is set."
OpenSPI();
WriteSPI(...);
ReadSPI(...);
CloseSPI(...);
OpenSPI();
WriteSPI(...);
ReadSPI(...);
CloseSPI(...);
Im stuck.. :-x I dont know what's next...
Im using the SPI debugger of proteus just to check what is going on in my SPI output (SDO).. but I dont understand what is happening the debugger what I see in only time and not the data I transmitted.. maybe I just dont know how to use the debugger... :grin:
Of course that would just make your life very boring, no challenge what so ever. And we wouldn't want that now would we?
yeah i see this stuff in the spi.h.. Im looking for the spi.c but i cant found it... hehe I want to read what's written in that file.. hehe
C:\Program Files\HI-TECH Software\PICC-18\PRO\9.66\sources\plib\spi
Keep in mind those library routines are for the PIC18 series and there are some significant differences between the PIC18 and PIC16 as far as initial configuration of registers.
#include <htc.h>
void SPI_init();
unsigned char ReadSPI( void );
void WriteSPI( unsigned char data_out );
void main()
{
char x;
CMCON = 0b111;
ADCON0 = 0b00000000;
SPI_init(); // initialize SPI mode
TRISAbits.TRISA0 = 0;
WriteSPI( 0x01 ); //writing to data to SSBUF
if(SSPBUF == 0x01) //checking written data
PORTAbits.RA0 = 0; // turn off LED when read data is equal to written data.
while(1);
}
void SPI_init()
{
/* Enables serial port and configures SCK, SDO, SDI and SS as serial port pins
SPI Master mode, clock = FOSC/64(3) */
SSPCON1 = 0b00100010;
/* Input data sampled at end of data output time
Transmit occurs on transition from active to Idle clock state */
SSPSTAT = 0b11000000;
TRISCbits.TRISC7 = 0; //SD0 set as output
TRISBbits.TRISB0 = 1; //SDI set as input
TRISBbits.TRISB1 = 0; //SCK set as output
TRISCbits.TRISC2 = 0; //CS set as output
}
void WriteSPI( unsigned char data_out )
{
SSPBUF = data_out; // write byte to SSPBUF register
while(BF==0);
}
unsigned char ReadSPI( void )
{
SSPBUF = 0x00; // initiate bus cycle
while ( !BF ); // wait until cycle complete
return ( SSPBUF ); // return with byte read
}
WriteSPI(0x01);
void WriteSPI( unsigned char data_out )
{
SSPBUF = data_out; // write byte to SSPBUF register
while(BF==0);
}
I am looking into it but did you see in the C18 manual there is an example how to use SPI with an EEPROM.
OpenSPI(SPI_FOSC_64, MODE_00, SMPEND); // Initialize MSSP to SPI mode and enable MSSP in SPI
WriteSPI(0x01); // Write a 0x01 byte to SSPBUF. Again, this message could be anything and depends on what device you are using.
SPI_CS = 1; // Allow Slave device to respond
while (!DataRdySPI()); // Wait until buffer is filled
x = ReadSPI(); // Read buffer
SPI_CS = 0; // Give back control to the master
CloseSPI(); // Disable the MSSP
while(1);
do you want to write the routing yourself or use inbuilt routine???
CloseSPI(); --// the content of this fucntion is just SSPEN: Master Synchronous Serial Port disable bit
DataRdySPI() -- // this is just BF
OpenSPI(SPI_FOSC_64, MODE_00, SMPEND); -- this are just
0010 = SPI Master mode, clock = FOSC/64(3)
0 = Transmit occurs on transition from Idle to active clock state
1 = Input data sampled at end of data output time
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?