ernestmyname
Member level 1
I have been trying to get SPI up between my PIC24 and a MCP3550 ADC. I have tried several different things but i can't figure out why I continually get a zero written in all three of the iWord registers. I have Chip Select at RB2, SDI at RB3, and SCK at RB4. Any suggestions?
Datasheet for ADC:
**broken link removed**
The PIC controller I'm using is the PIC24HJ64gp202
Any help or guidance would be greatly appreciated. I can't figure out what I'm leaving out. I have been stuck on this for several days. Thanks in advance!
Datasheet for ADC:
**broken link removed**
The PIC controller I'm using is the PIC24HJ64gp202
Code:
sbit Chip_Select at LATB2_bit;
int main() {
char Word,Buffer;
int iWord1, iWord2, iWord3,i;
//Unlock_IOLOCK(); //Not sure if I need this
PPS_Mapping(3, _INPUT, _SDI1);
PPS_Mapping(4, _OUTPUT, _SCK1OUT);
//Lock_IOLOCK(); //Not sure if I need this
TRISB = 0x0008; //RB3 input for SDI1. RP4 output for SCK1OUT
Chip_Select = 1;
delay_ms(250);
SPI1_Init_Advanced(_SPI_MASTER,_SPI_8_BIT,_SPI_PRESCALE_SEC_8,_SPI_PRESCALE_PRI_64,_SPI_SS_DISABLE,_SPI_DATA_SAMPLE_END,_SPI_CLK_IDLE_HIGH,_SPI_IDLE_2_ACTIVE);
Chip_Select = 0;
Chip_Select = 1;
delay_ms(10);
//Wait for ready_not to equal zero
while(PORTB.B3 != 0) {
Chip_Select = 1;
Chip_Select = 0;
}
iWord1 = SPI1_Read(Buffer);
delay_ms(10);
iWord2 = SPI1_Read(Buffer);
delay_ms(10);
iWord3 = SPI1_Read(Buffer);
delay_ms(10);
return 0;
}
Any help or guidance would be greatly appreciated. I can't figure out what I'm leaving out. I have been stuck on this for several days. Thanks in advance!