Hi there
I am working on Arduino and having problem regarding interfacing SCP1000 with arduino uno along with i2c protocol as i hv no knowledge of this.
can any boby help me in this regard???
regards
Asad
Be sure to click 'more' and select 'suggest as answer'!
If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!
Hi there
I am working on Arduino and having problem regarding interfacing SCP1000 with arduino uno along with i2c protocol as i hv no knowledge of this.
can any boby help me in this regard???
regards
Asad
howdy,
Here is the arduino code for the SCP1000:
// define spi bus pins #define SLAVESELECT 10 #define SPICLOCK 13 #define DATAOUT 11 //MOSI #define DATAIN 12 //MISO #define UBLB(a,b) ( ( (a) << 8) | (b) ) #define UBLB19(a,b) ( ( (a) << 16 ) | (b) ) //Addresses #define REVID 0x00 //ASIC Revision Number #define OPSTATUS 0x04 //Operation Status #define STATUS 0x07 //ASIC Status #define START 0x0A //Constant Readings #define PRESSURE 0x1F //Pressure 3 MSB #define PRESSURE_LSB 0x20 //Pressure 16 LSB #define TEMP 0x21 //16 bit temp char rev_in_byte; int temp_in; unsigned long pressure_lsb; unsigned long pressure_msb; unsigned long temp_pressure; unsigned long pressure; void setup() { byte clr; pinMode(DATAOUT, OUTPUT); pinMode(DATAIN, INPUT); pinMode(SPICLOCK,OUTPUT); pinMode(SLAVESELECT,OUTPUT); digitalWrite(SLAVESELECT,HIGH); //disable device SPCR = B01010011; //MPIE=0, SPE=1 (on), DORD=0 (MSB first), MSTR=1 (master), CPOL=0 (clock idle when low), CPHA=0 (samples MOSI on rising edge), SPR1=0 & SPR0=0 (500kHz) clr=SPSR; clr=SPDR; delay(10); Serial.begin(9600); delay(500); Serial.println("Initialize High Speed Constant Reading Mode"); write_register(0x03,0x09); } void loop() { rev_in_byte = read_register(REVID); pressure_msb = read_register(PRESSURE); pressure_msb &= B00000111; pressure_lsb = read_register16(PRESSURE_LSB); pressure = UBLB19(pressure_msb, pressure_lsb); pressure /= 4; Serial.print("PRESSURE ["); Serial.print(pressure, DEC); Serial.println("]"); temp_in = read_register16(TEMP); temp_in = temp_in / 20; temp_in = ((1.8) *temp_in) + 32; Serial.print("TEMP F ["); Serial.print(temp_in , DEC); Serial.println("]"); delay(1500); } char spi_transfer(volatile char data) { SPDR = data; // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission { }; return SPDR; // return the received byte } char read_register(char register_name) { char in_byte; register_name <<= 2; register_name &= B11111100; //Read command digitalWrite(SLAVESELECT,LOW); //Select SPI Device spi_transfer(register_name); //Write byte to device in_byte = spi_transfer(0x00); //Send nothing, but we should get back the register value digitalWrite(SLAVESELECT,HIGH); delay(10); return(in_byte); } float read_register16(char register_name) { byte in_byte1; byte in_byte2; float in_word; register_name <<= 2; register_name &= B11111100; //Read command digitalWrite(SLAVESELECT,LOW); //Select SPI Device spi_transfer(register_name); //Write byte to device in_byte1 = spi_transfer(0x00); in_byte2 = spi_transfer(0x00); digitalWrite(SLAVESELECT,HIGH); in_word = UBLB(in_byte1,in_byte2); return(in_word); } void write_register(char register_name, char register_value) { register_name <<= 2; register_name |= B00000010; //Write command digitalWrite(SLAVESELECT,LOW); //Select SPI device spi_transfer(register_name); //Send register location spi_transfer(register_value); //Send value to record into register digitalWrite(SLAVESELECT,HIGH); }
hope this helps,
Fidel Salinas
This code is implemented in spi protocol but the model i am using is
scp1000 d11 which works on i2c protocol.if u can help me in that,i will be
thankful to you
regards
Here is the code for the SCP1000 D11 using the i2c:
Deprecated code
Good Luck,
Fidel Salinas
AFS Technologies
AFS labs
Message was edited by: Fidel Salinas
After executing this code i got masage that this code having no void loop, no void setup and main exist so i tried a lot but it doesnot correct kindly add them and if someone have code of it kindly give me .... i am stuck in it ...
i shall be very thankful to you.
sorry that last code didn't work out for you, but I did find a library that didn't work with 1.0 and up, did a little bit of editing, everything compiled and now we should have a working i2c library for 1.0v. Here is a link SCP1000-D11 ,
Regards,
Fidel Salinas