]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
small fixes and first basic readout of MLX90393 via DS28E17 1-wire to I2C bridge.
authorAdrian Weber <adrian.a.weber@exp2.physik.uni-giessen.de>
Thu, 11 Feb 2021 13:53:31 +0000 (14:53 +0100)
committerAdrian Weber <adrian.a.weber@exp2.physik.uni-giessen.de>
Thu, 11 Feb 2021 13:53:31 +0000 (14:53 +0100)
atmega32u4/CbmRich_sensoring/DS28E17/DS28E17.c
atmega32u4/CbmRich_sensoring/DS28E17/DS28E17.h
atmega32u4/CbmRich_sensoring/main.c

index 13f123d0528ab6597af3b85c9a6f0cbd2dbb6fc1..dd4fb731acd14ff6aa48e7001e92f59cfe14f2d5 100644 (file)
@@ -1,9 +1,9 @@
 #include "DS28E17.h"
 
-int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr)
+int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t *status)
 {
        int wire_status;
-
+    status[0] = 0xd;
     uint8_t CRC_data_buf[] = {0,0,0,0};
        wire_status = owu_reset(wire);
        if (wire_status != OW_OK) return wire_status;
@@ -18,9 +18,10 @@ int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Ad
     //Send I2C Address
     //uint8_t addr_i2c = (I2C_Addr << 1) | 0x1;
     // not sure if Address has to be shifted or not
-    wire_status = owu_write_byte(wire, ((I2C_Addr << 1) | 0x0)); // 0x0: write
+    uint8_t i2c_add_shftd = ((I2C_Addr << 1) | 0x0);
+    wire_status = owu_write_byte(wire, i2c_add_shftd); // 0x0: write
        if (wire_status != OW_OK) return wire_status;
-    CRC_data_buf[1] = ((I2C_Addr << 1) | 0x0); // check if address has to be shifted or not
+    CRC_data_buf[1] = i2c_add_shftd; // check if address has to be shifted or not
 
     //Length of Data
     wire_status = owu_write_byte(wire, 0x01);
@@ -33,8 +34,13 @@ int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Ad
     CRC_data_buf[3] = 0x80;
 
     //CRC16
-    uint8_t CRC16 = ds28e17_crc16(CRC_data_buf,4);
-    wire_status = owu_write_byte(wire, CRC16);
+    uint16_t CRC16 = ds28e17_crc16(CRC_data_buf,4);
+    wire_status = owu_write_byte(wire, (CRC16&0xFF));
+       if (wire_status != OW_OK) return wire_status;
+
+    //CRC16
+    uint16_t CRC16_2 = ((CRC16>>8)&0xFF);
+    wire_status = owu_write_byte(wire, CRC16_2);
        if (wire_status != OW_OK) return wire_status;
 
     // read status: read bit until 0;
@@ -45,23 +51,192 @@ int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Ad
     } while(bit != 0);
 
     // read status
-    uint8_t status;
-    wire_status = owu_read_byte(wire, &status);
+    uint8_t r_status;
+    wire_status = owu_read_byte(wire, &r_status);
     if (wire_status != OW_OK) return wire_status;
-
+    status[0] = r_status;
     // read status write
-    wire_status = owu_read_byte(wire, &status);
+    wire_status = owu_read_byte(wire, &r_status);
     if (wire_status != OW_OK) return wire_status;    
+    status[1] = CRC16;//r_status;
 
        return wire_status;
 }
 
-int ds28e17_Write_Read_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr)
+int ds28e17_Write_Read_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t *status, uint8_t *answr)
 {
        int wire_status;
+    status[0] = 0xd;
+    uint8_t CRC_data_buf[] = {0,0,0,0,0};
+       wire_status = owu_reset(wire);
+       if (wire_status != OW_OK) return wire_status;
+
+       wire_status = owu_select_device(wire, OW_addr);
+       if (wire_status != OW_OK) return wire_status;
+
+       wire_status = owu_write_byte(wire, CMD_WRwS);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[0] = CMD_WRwS;
+
+    //Send I2C Address
+    //uint8_t addr_i2c = (I2C_Addr << 1) | 0x1;
+    // not sure if Address has to be shifted or not
+    uint8_t i2c_add_shftd = ((I2C_Addr << 1) | 0x0);
+    wire_status = owu_write_byte(wire, i2c_add_shftd); // 0x0: write
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[1] = i2c_add_shftd; // check if address has to be shifted or not
+
+    //Length of Data
+    wire_status = owu_write_byte(wire, 0x01);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[2] = 0x01;
+
+    //Data
+    wire_status = owu_write_byte(wire, 0x4F);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[3] = 0x4F;
+
+    //#bytes to read
+    wire_status = owu_write_byte(wire, 9);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[4] = 9;
+
+    //CRC16
+    uint16_t CRC16 = ds28e17_crc16(CRC_data_buf,5);
+    wire_status = owu_write_byte(wire, (CRC16&0xFF));
+       if (wire_status != OW_OK) return wire_status;
+
+    //CRC16
+    uint16_t CRC16_2 = ((CRC16>>8)&0xFF);
+    wire_status = owu_write_byte(wire, CRC16_2);
+       if (wire_status != OW_OK) return wire_status;
+
+    // read status: read bit until 0;
+    uint8_t bit;
+    do {
+        wire_status = read_bit(wire->driver, &bit);
+        if (wire_status != OW_OK) return wire_status;
+    } while(bit != 0);
+
+    // read status
+    uint8_t r_status;
+    wire_status = owu_read_byte(wire, &r_status);
+    if (wire_status != OW_OK) return wire_status;
+    status[0] = r_status;
+    // read status write
+    wire_status = owu_read_byte(wire, &r_status);
+    if (wire_status != OW_OK) return wire_status;    
+    status[1] = CRC16;//r_status;
+
+    uint8_t value;
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[0] = value;
+
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[1] = value;
+
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[2] = value;
+
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[3] = value;
+
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[4] = value;
+
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[5] = value;
+
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[6] = value;        
+
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[7] = value;
 
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[8] = value;
+
+       return wire_status;
+}
+
+int ds28e17_SM(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t *status, uint8_t *answr)
+{
+       int wire_status;
+    status[0] = 0xd;
+    uint8_t CRC_data_buf[] = {0,0,0,0,0};
        wire_status = owu_reset(wire);
+       if (wire_status != OW_OK) return wire_status;
+
+       wire_status = owu_select_device(wire, OW_addr);
+       if (wire_status != OW_OK) return wire_status;
+
+       wire_status = owu_write_byte(wire, CMD_WRwS);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[0] = CMD_WRwS;
+
+    //Send I2C Address
+    //uint8_t addr_i2c = (I2C_Addr << 1) | 0x1;
+    // not sure if Address has to be shifted or not
+    uint8_t i2c_add_shftd = ((I2C_Addr << 1) | 0x0);
+    wire_status = owu_write_byte(wire, i2c_add_shftd); // 0x0: write
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[1] = i2c_add_shftd; // check if address has to be shifted or not
+
+    //Length of Data
+    wire_status = owu_write_byte(wire, 0x01);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[2] = 0x01;
+
+    //Data
+    wire_status = owu_write_byte(wire, 0x3F);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[3] = 0x3F;
+
+    //#bytes to read
+    wire_status = owu_write_byte(wire, 1);
+       if (wire_status != OW_OK) return wire_status;
+    CRC_data_buf[4] = 1;
+
+    //CRC16
+    uint16_t CRC16 = ds28e17_crc16(CRC_data_buf,5);
+    wire_status = owu_write_byte(wire, (CRC16&0xFF));
+       if (wire_status != OW_OK) return wire_status;
+
+    //CRC16
+    uint16_t CRC16_2 = ((CRC16>>8)&0xFF);
+    wire_status = owu_write_byte(wire, CRC16_2);
+       if (wire_status != OW_OK) return wire_status;
 
+    // read status: read bit until 0;
+    uint8_t bit;
+    do {
+        wire_status = read_bit(wire->driver, &bit);
+        if (wire_status != OW_OK) return wire_status;
+    } while(bit != 0);
+
+    // read status
+    uint8_t r_status;
+    wire_status = owu_read_byte(wire, &r_status);
+    if (wire_status != OW_OK) return wire_status;
+    status[0] = r_status;
+    // read status write
+    wire_status = owu_read_byte(wire, &r_status);
+    if (wire_status != OW_OK) return wire_status;    
+    status[1] = CRC16;//r_status;
+
+    uint8_t value;
+    wire_status = owu_read_byte(wire, &value);
+    if (wire_status != OW_OK) return wire_status;    
+    answr[0] = value;
 
        return wire_status;
 }
index cd93a2cb3fee0123657ec3af729834a8eeeff378..105823c438693d6c03bcc0435eb43ba987441333 100644 (file)
 extern "C" {
 #endif
 
-int ds28e17_Write_Read_with_Stop(owu_struct_t *wire, uint8_t *addr, uint8_t I2C_Addr);
+int ds28e17_Write_Read_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t *status, uint8_t *answr);
 
-int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *addr, uint8_t I2C_Addr);
+int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *addr, uint8_t I2C_Addr, uint8_t *status);
+
+int ds28e17_SM(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t *status, uint8_t *answr);
 
 uint16_t ds28e17_crc16(uint8_t*, uint32_t);
 
index 61721439b3448ae3266e6b71044c7788a76d4e3a..7660fa91ed454c5e2bb30dfd0c19864534dfeffd 100644 (file)
@@ -94,7 +94,9 @@ ISR(TIMER0_OVF_vect) {
   time++;
   asm volatile("wdr");
 }    
-  
+
+
+// If sleep on ds28e17 is active, device does not show up on 1-wire.
 int main(void) {
   
 
@@ -244,6 +246,15 @@ int search_devices(owu_struct_t ow_Q[]){
       } else if (dev_addr[ow_line][dev_count[ow_line]-1][0] == 0x19 ){ //DS28E17
         dev_int_addr[ow_line][dev_count[ow_line]-1] = dev_sum[1];
         dev_sum[1]++;
+
+        //uint8_t lbuf[20];
+        //uint8_t stat[2] = {0xe,0xa};
+        //int nbytes2 = sprintf((char*) lbuf, "Reset MLX: %d\n", ds28e17_Write_with_Stop(&ow_Q[ow_line], dev_addr[ow_line][dev_count[ow_line]-1],0x0C,stat));
+        //usb_serial_write(lbuf,nbytes2);
+        //nbytes2 = sprintf((char*) lbuf, "DS28E17, status: %02x  %02x \n", stat[0], stat[1]);
+        //usb_serial_write(lbuf,nbytes2);
+        
+
       } else {
         //Error: Action to be defined.
       }      
@@ -272,10 +283,6 @@ int search_devices(owu_struct_t ow_Q[]){
          }
   }
 
-  
-  //ds28e17_Write_with_Stop(&ow_Q[0], dev_addr[0][dev_count[0]],0x45);
-
-
   return 0;
 }
 
@@ -294,6 +301,15 @@ int init_OW_measurements(owu_struct_t ow_Q[]){
         
 
       } else if (dev_addr[ow_line][dev_nbr][0] == 0x19) { // Device is DS28E17
+        
+        uint8_t lbuf[20];
+        uint8_t stat[2] = {0xe,0xa};
+        uint8_t answer = 0;
+        ds28e17_SM(&ow_Q[ow_line], dev_addr[ow_line][dev_nbr],0x0C,stat, &answer);
+        //int nbytes = sprintf((char*) lbuf, "INIT SM on MLX: %d\n", ds28e17_SM(&ow_Q[ow_line], dev_addr[ow_line][dev_nbr],0x0C,stat, &answer));
+        //usb_serial_write(lbuf,nbytes);
+        //nbytes = sprintf((char*) lbuf, "DS28E17, status: %02x  %02x  %02x\n", stat[0], stat[1], answer);
+        //usb_serial_write(lbuf,nbytes);
 
       } else {
         // error: Action to be defined
@@ -351,10 +367,31 @@ int OW_measurements(owu_struct_t ow_Q[]){
       ds_convert_device(&ow_Q[cur_meas_line], dev_addr[cur_meas_line][cur_meas_devNbr]);
 
     } else if (dev_addr[cur_meas_line][cur_meas_devNbr][0] == 0x19) { // Device is DS28E17
+
+      uint8_t lbuf[50];
+      uint8_t stat[2] = {0xe,0xa};
+      uint8_t value[10] = {0,0,0,0,0,0,0,0,0,0};
+      int nbytes = sprintf((char*) lbuf, "DS28E17: %d\n", ds28e17_Write_Read_with_Stop(&ow_Q[cur_meas_line], dev_addr[cur_meas_line][cur_meas_devNbr],0x0C,stat, value));
+      usb_serial_write(lbuf,nbytes);
+      nbytes = sprintf((char*) lbuf, "DS28E17, status: %02x  %02x %02x  %02x%02x  %02x%02x  %02x%02x  %02x%02x\n", stat[0], stat[1], value[0],
+                                                                                                                                     value[1],
+                                                                                                                                     value[2],
+                                                                                                                                     value[3],
+                                                                                                                                     value[4],
+                                                                                                                                     value[5],
+                                                                                                                                     value[6],
+                                                                                                                                     value[7],
+                                                                                                                                     value[8]);
+      usb_serial_write(lbuf,nbytes);
+
       send_Values(cur_meas_line,cur_meas_devNbr,'T',0x0000);
       send_Values(cur_meas_line,cur_meas_devNbr,'X',0x0000);
       send_Values(cur_meas_line,cur_meas_devNbr,'Y',0x0000);
       send_Values(cur_meas_line,cur_meas_devNbr,'Z',0x0000);
+
+      // Init new Single measurement (SM)
+      ds28e17_SM(&ow_Q[cur_meas_line], dev_addr[cur_meas_line][cur_meas_devNbr],0x0C,stat, value);
+
     } else {
       // error: Action to be defined
     }