#include "DS28E17.h"
-int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t *status)
+int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t wleng, uint8_t *wdata, uint8_t *status)
{
int wire_status;
status[0] = 0xd;
- uint8_t CRC_data_buf[] = {0,0,0,0};
+ const uint8_t CRC16bufSize = 3 + wleng;
+ uint8_t CRC_data_buf[CRC16bufSize];
wire_status = owu_reset(wire);
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);
+ wire_status = owu_write_byte(wire, wleng);
if (wire_status != OW_OK) return wire_status;
- CRC_data_buf[2] = 0x01;
+ CRC_data_buf[2] = wleng;
//Data
- wire_status = owu_write_byte(wire, 0x80);
- if (wire_status != OW_OK) return wire_status;
- CRC_data_buf[3] = 0x80;
-
- //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;
- uint8_t bit;
- do {
- wire_status = read_bit(wire->driver, &bit);
+ for (uint8_t i_data = 0; i_data < wleng; i_data++){
+ wire_status = owu_write_byte(wire, wdata[i_data]); // 0x80
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;
-
- return wire_status;
-}
-
-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;
+ CRC_data_buf[3+i_data] = wdata[i_data];
+ }
//CRC16
- uint16_t CRC16 = ds28e17_crc16(CRC_data_buf,5);
+ uint16_t CRC16 = ds28e17_crc16(CRC_data_buf,CRC16bufSize);
wire_status = owu_write_byte(wire, (CRC16&0xFF));
if (wire_status != OW_OK) return wire_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 ds28e17_Write_Read_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t wleng, uint8_t *wdata, uint8_t rleng, uint8_t *rdata, uint8_t *status)
{
int wire_status;
status[0] = 0xd;
- uint8_t CRC_data_buf[] = {0,0,0,0,0};
+ const uint8_t crc_buf_size = 4+wleng;
+ uint8_t CRC_data_buf[crc_buf_size];
wire_status = owu_reset(wire);
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);
+ wire_status = owu_write_byte(wire, wleng);
if (wire_status != OW_OK) return wire_status;
- CRC_data_buf[2] = 0x01;
+ CRC_data_buf[2] = wleng;
//Data
- wire_status = owu_write_byte(wire, 0x3F);
- if (wire_status != OW_OK) return wire_status;
- CRC_data_buf[3] = 0x3F;
+ for (uint8_t i_wdata = 0; i_wdata < wleng; i_wdata++) {
+ wire_status = owu_write_byte(wire, wdata[i_wdata]);
+ if (wire_status != OW_OK) return wire_status;
+ CRC_data_buf[3+i_wdata] = wdata[i_wdata];
+ }
//#bytes to read
- wire_status = owu_write_byte(wire, 1);
+ wire_status = owu_write_byte(wire, rleng);
if (wire_status != OW_OK) return wire_status;
- CRC_data_buf[4] = 1;
+ CRC_data_buf[3+wleng] = rleng;
//CRC16
- uint16_t CRC16 = ds28e17_crc16(CRC_data_buf,5);
+ uint16_t CRC16 = ds28e17_crc16(CRC_data_buf,crc_buf_size);
wire_status = owu_write_byte(wire, (CRC16&0xFF));
if (wire_status != OW_OK) return wire_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;
+ // read data
+ for (uint8_t i_rdata = 0; i_rdata < rleng; i_rdata++){
+ wire_status = owu_read_byte(wire, &rdata[i_rdata]);
+ if (wire_status != OW_OK) return wire_status;
+ }
return wire_status;
}
extern "C" {
#endif
-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_Read_with_Stop(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t wleng, uint8_t *wdata,uint8_t rleng, uint8_t *rdata, uint8_t *status);
-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);
+int ds28e17_Write_with_Stop(owu_struct_t *wire, uint8_t *addr, uint8_t I2C_Addr, uint8_t wleng, uint8_t *wdata, uint8_t *status);
uint16_t ds28e17_crc16(uint8_t*, uint32_t);
--- /dev/null
+#include "MLX90393.h"
+
+int MLX90393_convert_TXYZ_SM(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t rleng, uint8_t *rdata, uint8_t *status){
+ uint8_t wdata_SM[1] = {0x3F};
+ return ds28e17_Write_Read_with_Stop(wire,OW_addr,I2C_Addr,0x1,wdata_SM,rleng,rdata,status);
+}
+
+int MLX90393_read_TXYZ(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t rleng, uint8_t *rdata, uint8_t *status){
+ uint8_t wdata_SM[1] = {0x4F};
+ return ds28e17_Write_Read_with_Stop(wire,OW_addr,I2C_Addr,0x1,wdata_SM,rleng,rdata,status);
+}
\ No newline at end of file
--- /dev/null
+#ifndef INCLUDE_MLX90393_H_
+#define INCLUDE_MLX90393_H_
+
+
+#include <stdint.h>
+#include "DS28E17.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+int MLX90393_convert_TXYZ_SM(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t rleng, uint8_t *rdata, uint8_t *status);
+
+int MLX90393_read_TXYZ(owu_struct_t *wire, uint8_t *OW_addr, uint8_t I2C_Addr, uint8_t rleng, uint8_t *rdata, uint8_t *status);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* INCLUDE_MLX90393_H_ */
\ No newline at end of file
MCU = atmega32u4
FORMAT = ihex
TARGET = main
-SRC = $(TARGET).c usb_serial.c lib/1wire/drivers/ow_driver_avr_gpio.c lib/1wire/dallas/dallas.c lib/1wire/onewire/onewire.c DS28E17/DS28E17.c
+SRC = $(TARGET).c usb_serial.c lib/1wire/drivers/ow_driver_avr_gpio.c lib/1wire/dallas/dallas.c lib/1wire/onewire/onewire.c DS28E17/DS28E17.c MLX90393/MLX90393.c
ASRC =
OPT = 2
PORT=/dev/ttyACM0
# Place -I options here
#CINCS =
-CINCS = -I. -I./lib/1wire/dallas -I./lib/1wire/onewire -I./lib/1wire/drivers -I./DS28E17
+CINCS = -I. -I./lib/1wire/dallas -I./lib/1wire/onewire -I./lib/1wire/drivers -I./DS28E17 -I./MLX90393
CDEBUG = -g$(DEBUG)
#include "onewire.h"
#include "dallas.h"
#include "DS28E17.h"
+#include "MLX90393.h"
#include <stdio.h>
//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));
+ //uint wdata[1] = 0x80;
+ //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,1,wdata,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 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);
+ MLX90393_convert_TXYZ_SM(&ow_Q[ow_line], dev_addr[ow_line][dev_nbr],0x0C,0x1,&answer,stat);
+ //uint8_t lbuf[20];
//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);
#ifdef DEBUG_USB_OUT
int nbytes = sprintf((char*) tx_test_buf, "\t Start Measurement: %x%x%x%x%x%x%x%x\r\n", dev_addr[ow_line][dev_nbr][0],
- dev_addr[ow_line][dev_nbr][1],
- dev_addr[ow_line][dev_nbr][2],
- dev_addr[ow_line][dev_nbr][3],
- dev_addr[ow_line][dev_nbr][4],
- dev_addr[ow_line][dev_nbr][5],
- dev_addr[ow_line][dev_nbr][6],
- dev_addr[ow_line][dev_nbr][7]);
+ dev_addr[ow_line][dev_nbr][1],
+ dev_addr[ow_line][dev_nbr][2],
+ dev_addr[ow_line][dev_nbr][3],
+ dev_addr[ow_line][dev_nbr][4],
+ dev_addr[ow_line][dev_nbr][5],
+ dev_addr[ow_line][dev_nbr][6],
+ dev_addr[ow_line][dev_nbr][7]);
usb_serial_write(tx_test_buf,nbytes);
#endif
}
} 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 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));
+ //uint8_t wdata[1] = {0x4F};
+ int nbytes = sprintf((char*) lbuf, "DS28E17: %d\n", MLX90393_read_TXYZ(&ow_Q[cur_meas_line],
+ dev_addr[cur_meas_line][cur_meas_devNbr],
+ 0x0C,
+ 0x9,
+ value,
+ stat));
+
+ send_Values(cur_meas_line,cur_meas_devNbr,'T',(uint16_t) ((value[1] << 8) | value[2]));
+ send_Values(cur_meas_line,cur_meas_devNbr,'X',(uint16_t) ((value[3] << 8) | value[4]));
+ send_Values(cur_meas_line,cur_meas_devNbr,'Y',(uint16_t) ((value[5] << 8) | value[6]));
+ send_Values(cur_meas_line,cur_meas_devNbr,'Z',(uint16_t) ((value[7] << 8) | value[8]));
+
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[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);
+ MLX90393_convert_TXYZ_SM(&ow_Q[cur_meas_line],
+ dev_addr[cur_meas_line][cur_meas_devNbr],
+ 0x0C,
+ 0x1,
+ value,
+ stat);
} else {
// error: Action to be defined
delay_us(5); // TO DO: change to ASM command
}
- uint8_t nbytes = sprintf((char*) txbuf, "V%02x%02x%c%x\n",dev_addr[line][devNbr][0],
+ uint8_t nbytes = sprintf((char*) txbuf, "V%02x%02x%c%04x\n",dev_addr[line][devNbr][0],
dev_int_addr[line][devNbr],
(char) valType,
value);