//#define DEBUG_USB_OUT
// BEGIN define 1-wire parameters
-#define MAX_OW_DEV_COUNT_PER_PIN 10
+#define MAX_OW_DEV_COUNT_PER_PIN 10 // DS18B20 + MLX90393
#define NUM_1W_PINS 3
typedef enum {
DS28E17
} OW_DEV_CODE_t;
+uint8_t MLX90393_I2C_Addr[] = {0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13,
+ 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1A, 0x1B};
+
uint8_t scratch_pad[__SCR_LENGTH];
uint8_t dev_count[NUM_1W_PINS];
-uint8_t dev_addr[NUM_1W_PINS][MAX_OW_DEV_COUNT_PER_PIN][8]; // UID
+uint8_t dev_addr[NUM_1W_PINS][MAX_OW_DEV_COUNT_PER_PIN][9]; // UID // last is I2CAddress
uint8_t dev_int_addr[NUM_1W_PINS][MAX_OW_DEV_COUNT_PER_PIN]; // int. Address of Device Type
uint8_t DS18B20_scratch_pad[__SCR_LENGTH];
int search_devices(owu_struct_t []);
int init_OW_measurements(owu_struct_t []);
int OW_measurements(owu_struct_t []);
-void send_Address(uint8_t line , uint8_t devNbr, uint8_t I2C_add);
+void send_Address(uint8_t line , uint8_t devNbr);
void send_Values(uint8_t line , uint8_t devNbr, uint8_t valType, uint16_t value);
dev_count[i] = 0;
for (uint8_t j = 0; j < MAX_OW_DEV_COUNT_PER_PIN; ++j){
dev_int_addr[i][j] = 0;
- for (uint8_t k = 0; k < 8; ++k){
+ for (uint8_t k = 0; k < 9; ++k){
dev_addr[i][j][k] = 0;
}
}
uint8_t dev_sum[] = {0,0};
for (uint8_t ow_line = 0; ow_line < NUM_1W_PINS; ++ow_line){
while(owu_search(&ow_Q[ow_line], dev_addr[ow_line][dev_count[ow_line]])) {
- dev_count[ow_line]++;
- uint8_t I2C_add = 0x00;
- if (dev_addr[ow_line][dev_count[ow_line]-1][0] == 0x28 ) { // DS18B20
+
+ if (dev_addr[ow_line][dev_count[ow_line]][0] == 0x28 ) { // DS18B20
+ dev_count[ow_line]++;
dev_int_addr[ow_line][dev_count[ow_line]-1] = dev_sum[0];
dev_sum[0]++;
- } 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]++;
-
+ dev_addr[ow_line][dev_count[ow_line]][8] = 0x00; // Set I2C Address to 0.
+ send_Address(ow_line, dev_count[ow_line]-1);
+ } else if (dev_addr[ow_line][dev_count[ow_line]][0] == 0x19 ){ //DS28E17
+ {
+ uint8_t stat[2] = {0,0}; uint8_t answer = 0;
+ for (uint8_t i_i2c = 0; i_i2c < 16 ;i_i2c++){
+ MLX90393_convert_TXYZ_SM(&ow_Q[ow_line], dev_addr[ow_line][dev_count[ow_line]],MLX90393_I2C_Addr[i_i2c],0x1,&answer,stat);
+ //uint8_t lbuf[30];
+ if (stat[0] == 0) {
+ //int nbytes2 = sprintf((char*) lbuf, "DS28E17, status: %02x %02x %02x\n", stat[0], stat[1], answer);
+ //usb_serial_write(lbuf,nbytes2);
+ dev_int_addr[ow_line][dev_count[ow_line]] = dev_sum[1];
+ dev_sum[1]++;
+ dev_count[ow_line]++;
+ dev_addr[ow_line][dev_count[ow_line]-1][8] = MLX90393_I2C_Addr[i_i2c];
+ send_Address(ow_line, dev_count[ow_line]-1);
+ // prepare Address for potetial next MLX90393 device
+ for (uint8_t i_cpy = 0; i_cpy < 8; i_cpy++){
+ dev_addr[ow_line][dev_count[ow_line]][i_cpy] = dev_addr[ow_line][dev_count[ow_line]-1][i_cpy];
+ }
+ dev_addr[ow_line][dev_count[ow_line]][8] = 0x00;
+ }
+ }
+ }
//uint8_t lbuf[20];
//uint8_t stat[2] = {0xe,0xa};
//uint wdata[1] = 0x80;
//Error: Action to be defined.
}
- send_Address(ow_line, dev_count[ow_line]-1, I2C_add);
+
#ifdef DEBUG_USB_OUT
int nbytes = sprintf((char*) tx_test_buf, "Devices found on line %d : %d\n", ow_line, dev_count[ow_line]);
} else if (dev_addr[ow_line][dev_nbr][0] == 0x19) { // Device is DS28E17
- uint8_t stat[2] = {0xe,0xa};
+ uint8_t stat[2] = {0,0};
uint8_t answer = 0;
- MLX90393_convert_TXYZ_SM(&ow_Q[ow_line], dev_addr[ow_line][dev_nbr],0x0C,0x1,&answer,stat);
+ MLX90393_convert_TXYZ_SM(&ow_Q[ow_line], dev_addr[ow_line][dev_nbr],dev_addr[ow_line][dev_nbr][8],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);
//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,
+ dev_addr[cur_meas_line][cur_meas_devNbr][8],
0x9,
value,
stat));
// Init new Single measurement (SM)
MLX90393_convert_TXYZ_SM(&ow_Q[cur_meas_line],
dev_addr[cur_meas_line][cur_meas_devNbr],
- 0x0C,
+ dev_addr[cur_meas_line][cur_meas_devNbr][8],
0x1,
value,
stat);
return 0;
}
-void send_Address(uint8_t line , uint8_t devNbr, uint8_t I2C_add){
+void send_Address(uint8_t line , uint8_t devNbr){
// Definition of Address message:
// A<FF><II><xxxxxxxxxxxx><CC>\n
// A : char for Address message
dev_addr[line][devNbr][4],
dev_addr[line][devNbr][5],
dev_addr[line][devNbr][6],
- I2C_add);
+ dev_addr[line][devNbr][8]);
usb_serial_write(txbuf,nbytes);
// Send via UART