Cekobidonq
Newbie level 3
SPI read Problem with PIC18F4550
Hello all,
I'm having a problem with the SPI interface on a PIC18F4550. I am trying to read data from a 24-bit A/D converter (ADS1271IPWG4). I have set up the SSPCON1 and SSPSTAT registers and I am sending a byte through the SDO pin to the ADC to produce the clock signal on pin SCK that will synchronize the data transfer. When I measure the waveform on pin SDI of the PIC, I get well synched serial data, but when I try to read the SSPBUF register I get nothing. My code is the following:
I am using MikroC Pro compiler. I also tried using the SPI1_Read function from the compiler's library, but with the same result.
If you have any idea what I'm doing wrong, please reply.
Best regards,
Tsvetan
Hello all,
I'm having a problem with the SPI interface on a PIC18F4550. I am trying to read data from a 24-bit A/D converter (ADS1271IPWG4). I have set up the SSPCON1 and SSPSTAT registers and I am sending a byte through the SDO pin to the ADC to produce the clock signal on pin SCK that will synchronize the data transfer. When I measure the waveform on pin SDI of the PIC, I get well synched serial data, but when I try to read the SSPBUF register I get nothing. My code is the following:
Code:
void main() {
short sample, buffer;
TRISA=0x00;
TRISB=0x01;
TRISC=0x00;
while(1)
{
SSPCON1=0b00100010;
PORTA.B5=0;
SSPCON1.WCOL=0;
SSPSTAT.BF=0;
delay_us(10);
SSPBUF=0xff;
if(SSPSTAT.BF)
{
sample=SSPBUF;
SSPSTAT.BF=0;
SSPCON1.WCOL=0;
}
delay_us(500);
PORTC=sample;
}
}
I am using MikroC Pro compiler. I also tried using the SPI1_Read function from the compiler's library, but with the same result.
If you have any idea what I'm doing wrong, please reply.
Best regards,
Tsvetan
Last edited: