Siddft
Junior Member level 2
- Joined
- Oct 19, 2012
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Bangalore
- Activity points
- 1,432
Hello all,
I am doing Single master multiple slave implemetation.
Master - PIC18F4550
Slave - PIC18F4520
A potentiometer is connected to the Slave. Slave will convert the Potentiometer value to digital and communicate with the master using SPI protocol.
I am getting 8bit data(ADRESH -- Left justified)correctly from slave. But I have to get 10bit data(ADRESH - 8bit, ADRESL - 2bit).
How to get 10bit data????
Here is the sample code for master and slave
Master
------
LATDbits.LATD0 = 0; //Slave select
while(SSPSTATbits.BF == 0); //wait untill the buffer is full
var1 = SSPBUF;
LATDbits.LATD0 = 1;
delay
LATDbits.LATD0 = 0;
while(SSPSTATbits.BF == 0);
var2 = SSPBUF;
LATDbits.LATD0 = 1;
delay
Slave
-----
ADCON0bits.CHS0 = 0;
ADCON0bits.CHS1 = 0;
ADCON0bits.CHS2 = 0;
ADCON0bits.CHS3 = 0;
ADCON0bits.GO = 1;
while (ADCON0bits.NOT_DONE);
ch1 = ADRESL;
ch2 = ADRESH;
SSPCON1bits.WCOL = 0;
while(PORTAbits.RA5 == 1);//wait untill slave select
SSPBUF = ch1;
while(SSPSTATbits.BF == 0);
delay
SSPCON1bits.WCOL = 0;
while(PORTAbits.RA5 == 1);//wait untill slave select
SSPBUF = ch2;
while(SSPSTATbits.BF == 0);
delay
The above code works fine for 8bit data but not giving 10bit data(May be because of some sync problem), So how to get 10bit data.
please share me if you have any sample code.
Advance thanks for your help.
regards,
Sid
I am doing Single master multiple slave implemetation.
Master - PIC18F4550
Slave - PIC18F4520
A potentiometer is connected to the Slave. Slave will convert the Potentiometer value to digital and communicate with the master using SPI protocol.
I am getting 8bit data(ADRESH -- Left justified)correctly from slave. But I have to get 10bit data(ADRESH - 8bit, ADRESL - 2bit).
How to get 10bit data????
Here is the sample code for master and slave
Master
------
LATDbits.LATD0 = 0; //Slave select
while(SSPSTATbits.BF == 0); //wait untill the buffer is full
var1 = SSPBUF;
LATDbits.LATD0 = 1;
delay
LATDbits.LATD0 = 0;
while(SSPSTATbits.BF == 0);
var2 = SSPBUF;
LATDbits.LATD0 = 1;
delay
Slave
-----
ADCON0bits.CHS0 = 0;
ADCON0bits.CHS1 = 0;
ADCON0bits.CHS2 = 0;
ADCON0bits.CHS3 = 0;
ADCON0bits.GO = 1;
while (ADCON0bits.NOT_DONE);
ch1 = ADRESL;
ch2 = ADRESH;
SSPCON1bits.WCOL = 0;
while(PORTAbits.RA5 == 1);//wait untill slave select
SSPBUF = ch1;
while(SSPSTATbits.BF == 0);
delay
SSPCON1bits.WCOL = 0;
while(PORTAbits.RA5 == 1);//wait untill slave select
SSPBUF = ch2;
while(SSPSTATbits.BF == 0);
delay
The above code works fine for 8bit data but not giving 10bit data(May be because of some sync problem), So how to get 10bit data.
please share me if you have any sample code.
Advance thanks for your help.
regards,
Sid