- Fri Feb 06, 2009 4:04 am
#65488
Hi all,
First time in the forums, but have been following the site for a while. Keep up the good work!
I'm trying to get a PIC24 talking to a VTI SCP1000 barometric pressure sensor. I've used the code samples from this forum, VTI and other sources to try and clobber something together using the Hi-tech dsPICC compiler. I've sucessfully got comms using the PIC24Fs SPI uart and can read the STATUS, REV_ID registers.
The issue I'm having is after software resetting and initialising a read, the SCP does not seem to put the DRDY pin high, so my program gets stuck...
I've checked that I've set the PIC pin correctly as an input and have tried the seocnd SCP I have. Do I need to set the pullup resistor on the pin? No one elses circutis suggest that.
Any ideas?
EDIT:
I've included the main code below. The data being sent for the 'High Resolution Read' seems good on the scope... Will play with that just to make sure I'm not doing something silly.
First time in the forums, but have been following the site for a while. Keep up the good work!
I'm trying to get a PIC24 talking to a VTI SCP1000 barometric pressure sensor. I've used the code samples from this forum, VTI and other sources to try and clobber something together using the Hi-tech dsPICC compiler. I've sucessfully got comms using the PIC24Fs SPI uart and can read the STATUS, REV_ID registers.
The issue I'm having is after software resetting and initialising a read, the SCP does not seem to put the DRDY pin high, so my program gets stuck...
I've checked that I've set the PIC pin correctly as an input and have tried the seocnd SCP I have. Do I need to set the pullup resistor on the pin? No one elses circutis suggest that.
Any ideas?
EDIT:
I've included the main code below. The data being sent for the 'High Resolution Read' seems good on the scope... Will play with that just to make sure I'm not doing something silly.
Code: Select all
//FROM MAIN
{
write_uart_string("\n\r");
write_uart_string("Power up...\n\r");
timer_wait(200); //Make sure power is settled for SCP
//Perform software reset
printf("Resetting...\n\r");
write_register(0x06, 0x01); //RESET ASIC
timer_wait(60);
//Check comms
read_register8(0x00); //Get ASIC REVISION
printf("REV_ID: %d\n\r",byte_returned);
read_register8(0x1F); //Get Checksum
printf("CHECKSUM: %d\n\r",byte_returned);
read_register8(0x07); //Get STATUS
printf("STATUS: %d\n\r",byte_returned);
printf("Set to high res mode\n\r");
write_register(0x03, 0x0A); //Set to high res mode
timer_wait(100);
read_register8(0x04); //Get OPSTATUS
printf("OPSTATUS: %d\n\r",byte_returned);
read_register8(0x07); //Get STATUS
printf("STATUS: %d\n\r",byte_returned);
//STICKS HERE?!
while(DRDY == 0)
{
timer_wait(100);
} //Wait for conversion to compelte
//STICKS HERE?!
temp_data = read_register16(0x21); //Get TEMPERATURE
temp_data = temp_data & 0x3fff;
temp_data = temp_data/20;
printf("TEMP: %d\n\r",int_returned);
while(1)
{
RIGHT_LED = 1; //Show read is complete
}
}
//SPI SEND/RECV 1 byte
//===============
char spi_comm(char spi_byte_out)
{
SPI1BUF = spi_byte_out;
while(!(SPI1STAT==0x8001)){}; //Wait for RX buffer to fill up (tx complete)
return (SPI1BUF);
}
//WRITE 8 bit REGISTER
//===================
void write_register(char register_name, char register_value)
{
register_name <<= 2;
register_name &= 0b11111100; //Read Command
CS = 0;
spi_comm(register_name); //Write byte to device, ignore returned byte
spi_comm(register_value); //Write byte to device, ignore returned byte
CS = 1;
return;
}
//READ 8 bit REGISTER
//===================
char read_register8(char register_name)
{
register_name <<= 2;
register_name &= 0b11111100; //Read Command
CS = 0;
spi_comm(register_name); //Write byte to device, ignore returned byte
byte_returned = spi_comm(0x00); //Send 8 zeros and get back result
CS = 1;
return(byte_returned);
}
//READ 16 bit REGISTER
//===================
int read_register16(char register_name)
{
char b1,b2; //temp vars
register_name <<= 2;
register_name &= 0b11111100; //Read Command
CS = 0;
spi_comm(register_name); //Write byte to device, ignore returned byte
b1 = spi_comm(0x00); //Send 8 zeros and get back result
b2 = spi_comm(0x00); //Send 8 zeros and get back result
CS = 1;
int_returned = b1;
int_returned <<= 8;
int_returned |= b2;
return(int_returned);
}
I'm using all the rights bits, but nescessarily in the right order...