#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;
//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);
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;
} 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;
}
time++;
asm volatile("wdr");
}
-
+
+
+// If sleep on ds28e17 is active, device does not show up on 1-wire.
int main(void) {
} 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.
}
}
}
-
- //ds28e17_Write_with_Stop(&ow_Q[0], dev_addr[0][dev_count[0]],0x45);
-
-
return 0;
}
} 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
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
}