• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SPI Hardware 16Bit

Status
Not open for further replies.

Suraj143

Active Member
I use PIC 16F88 Hardware SPI.I want to write a 16bit value.How to do it?

SPI_Write(0x07E4);

This is the code for 8bits.I need to convert it to 16bit.

Code:
unsigned char SPI_Write(unsigned char val)
                 {                
                 SSPSTAT.BF=0;
                 SSPBUF = val;
                 while(SSPSTAT.BF==0);
                 return  SSPBUF;
                 }
 

Suraj143

Active Member
You mean like this?

Code:
        CS = 0;
        SPI_Write(High_Byte);
        SPI_Write(LOW_Byte);
        CS = 1;

unsigned char SPI_Write(unsigned char val)
                 {                
                 SSPSTAT.BF=0;
                 SSPBUF = val;
                 while(SSPSTAT.BF==0);
                 return  SSPBUF;
                 }
 

Jon Wilder

Active Member
Or you can do -
Code:
unsigned int writeSpi(unsigned int data){
    PIR1bits.SSPIF = 0;
    SSPBUF = (data / 256) & 0x00FF;
    while(!PIR1bits.SSPIF);
    unsigned int returndata = SSPBUF * 256;
    PIR1bits.SSPIF = 0;
    SSPBUF = data & 0x00FF;
    while(!PIR1bits.SSPIF);
    returndata += SSPBUF;
    return returndata;
}
This allows you to pass the complete 16-bit value to the procedure in a single procedure call. The procedure will return a 16-bit value.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top