
This is the code for me to search for the ROMID of DE28E18.
#define MAX_DEVICES 16
uint8_t found_devices[MAX_DEVICES][8];
uint8_t device_count = 0;
uint8_t current_device = 0;
void search_all_devices(void) {
uint8_t rom_no[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
device_count = 0;
bool reset_search = true;
while (device_count < MAX_DEVICES) {
bool last_device = OneWire_Search(rom_no, reset_search);
bool valid_device = false;
for (int i=0; i<8; i++) {
if (rom_no[i] != 0xFF) {
valid_device = true;
break;
}
}
if (valid_device) {
memcpy(found_devices[device_count], rom_no, 8);
printf("Found device %d: ", device_count+1);
for (int i=0; i<8; i++) {
printf("%02X ", found_devices[device_count][i]);
}
printf("\n");
device_count++;
reset_search = false;
} else {
break;
}
if (last_device) {
break;
}
}
printf("Total devices found: %d\n", device_count);
}
void DS2485_OneWireSearch(uint8_t *romId, uint8_t code, bool ow_reset, bool ignore, bool search_rst, bool *flag)
{
MASTER_SPEED_CONFIGURATIONS master_speed;
double one_wire_time;
double ow_rst_time;
double t_slot;
double t_rstl;
double t_rsth;
double t_w0l;
double t_rec;
DS2485_Get_Master_Speed(&master_speed);
if(master_speed != STANDARD)
{
DS2485_Get_tRSTL(&t_rstl, OVERDRIVE);
DS2485_Get_tRSTH(&t_rsth, OVERDRIVE);
DS2485_Get_tW0L(&t_w0l, OVERDRIVE);
DS2485_Get_tREC(&t_rec, OVERDRIVE);
}
else
{
DS2485_Get_tRSTL(&t_rstl, STANDARD);
DS2485_Get_tRSTH(&t_rsth, STANDARD);
DS2485_Get_tW0L(&t_w0l, STANDARD);
DS2485_Get_tREC(&t_rec, STANDARD);
}
t_slot = t_w0l + t_rec;
ow_rst_time = t_rstl + t_rsth;
one_wire_time = ((t_slot * 8) * (64));
if(ow_reset)
{
one_wire_time += ow_rst_time;
}
const int txLength = 4;
const int delay = tOP + (tSEQ*(64 + ow_reset)) + one_wire_time;
const int rxLength = 11;
uint8_t packet[txLength];
uint8_t response[rxLength];
packet[0] = DS2485_OW_SEARCH_CMD;
packet[1] = sizeof(packet) - 2;
packet[2] = (search_rst << 2) | (ignore << 1) | (ow_reset << 0);
packet[3] = code;
DS2485_I2C_Write(packet, sizeof(packet));
delay_us(delay);
// HAL_Delay(delay / 1000);
DS2485_I2C_Read(response, sizeof(response));
memcpy(&romId[0], &response[2], 8);
*flag = response[10];
//printf("******************* Last device flag: %02x\n\r", response[10]);
if(response[1] == 0xAA)
{
//printf("One Wire search SUCCESSED!\n\r");
}
else
{
printf("One Wire search FAILED! Code is %02x\n\r", response[1]);
}
}
I currently have 16 slave nodes carrying DS28E18 chips, which are connected together. I am using DS2485 as the 1-Wire chip for the master node, but can only read the results shown in the picture. When there is only one slave node, of course, its ROMID can be read. I am curious why the current code cannot read the ROMIDs of multiple connected slave nodes.
If anyone could help me, I would be extremely grateful!