marcel van de Kamp
/
ADS8320V3_example
program for external ADC ADS8320 Based on the program for the SCP1000. Still figuring out timing issues
Embed:
(wiki syntax)
Show/hide line numbers
ads8320.cpp
00001 00002 00003 #include "ads8320.h" 00004 00005 ads8320::ads8320(PinName mosi, PinName miso, PinName sclk, PinName cs) 00006 : m_spi(mosi, miso, sclk) 00007 , m_cs(cs) { 00008 m_cs=1; 00009 m_spi.frequency(1000000); // the fastest of the sensor 00010 m_spi.format(8, 0); // duda son dos palabras de 8 bits? 00011 // wait(0.5); 00012 //------------------------------------------------ 00013 // pc.printf("RESET\r\n"); 00014 write_register(0x06,0x01); 00015 // wait(0.5); 00016 00017 // pc.printf("Initialize High Resolution Constant Reading Mode\r\n"); 00018 write_register(0x03,0x0A); 00019 //wait(0.5); 00020 } 00021 00022 00023 unsigned int ads8320::readTemperature() { //was float 00024 unsigned int temp_in = read_register16(TEMP); 00025 // temp_in /= 20; 00026 unsigned int Ti = temp_in; 00027 return Ti; //return temp_in; 00028 } 00029 00030 void ads8320::write_register(char register_name, char register_value) { 00031 register_name <<= 2; 00032 register_name |= 0x02; //write command 00033 m_cs=0; //Select SPI device 00034 m_spi.write(register_name); //Send register location 00035 m_spi.write(register_value); //Send value to record into register 00036 m_cs=1; 00037 } 00038 00039 unsigned int ads8320::read_register16(char register_name) { 00040 register_name <<= 2; 00041 register_name &= 0xFC; //Read command 00042 m_cs=0; //Select SPI Device 00043 m_spi.write(register_name); //Write byte to device 00044 unsigned int in_byte1 = m_spi.write(0x00); //(was zonder unsigned) 00045 unsigned int in_byte2 = m_spi.write(0x00); 00046 m_cs=1; 00047 //float in_word= (in_byte1<<=8) | (in_byte2); 00048 unsigned int in_word= (in_byte1<<=8) | (in_byte2); 00049 return(in_word); 00050 }
Generated on Wed Aug 24 2022 02:26:52 by 1.7.2