niijyeni@yahoo.com [nuttx]
2018-03-19 02:47:22 UTC
Hi, AllïŒ
When I use 1-wire to communicate, I always do not read the address of Ds18b20 correctly, here is my test code, please help me to confirm if I made a mistake, and fix this error.
int ret;
int i;
FAR struct onewire_dev_s* onewire_dev = stm32_1wireinitialize(3);
if (onewire_dev == NULL) {
printf("stm32_1wireinitialize return NULL!\n");
return EXIT_FAILURE;
}
if (ONEWIRE_RESET(onewire_dev) == OK) {
uint8_t txbuff[] = { 0x33 };
printf("Found!\n");
if (ONEWIRE_WRITE(onewire_dev, txbuff, sizeof(txbuff)) == OK) {
uint8_t rxbuff[8];
usleep(10);
printf("Write OK!\n");
if (ONEWIRE_READ(onewire_dev, rxbuff, sizeof(rxbuff)) == OK) {
printf("Read OK!\n");
for (i = 0; i < sizeof(rxbuff); i++) {
printf("%x ", rxbuff[i]);
}
printf("\n");
} else {
printf("Read ERROR!\n");
}
} else {
printf("Write ERROR!\n");
}
} else {
printf("Not found!\n");
}
stm32_1wireuninitialize(onewire_dev);
printf("Terminating!\n");
fflush(stdout);
When I use 1-wire to communicate, I always do not read the address of Ds18b20 correctly, here is my test code, please help me to confirm if I made a mistake, and fix this error.
int ret;
int i;
FAR struct onewire_dev_s* onewire_dev = stm32_1wireinitialize(3);
if (onewire_dev == NULL) {
printf("stm32_1wireinitialize return NULL!\n");
return EXIT_FAILURE;
}
if (ONEWIRE_RESET(onewire_dev) == OK) {
uint8_t txbuff[] = { 0x33 };
printf("Found!\n");
if (ONEWIRE_WRITE(onewire_dev, txbuff, sizeof(txbuff)) == OK) {
uint8_t rxbuff[8];
usleep(10);
printf("Write OK!\n");
if (ONEWIRE_READ(onewire_dev, rxbuff, sizeof(rxbuff)) == OK) {
printf("Read OK!\n");
for (i = 0; i < sizeof(rxbuff); i++) {
printf("%x ", rxbuff[i]);
}
printf("\n");
} else {
printf("Read ERROR!\n");
}
} else {
printf("Write ERROR!\n");
}
} else {
printf("Not found!\n");
}
stm32_1wireuninitialize(onewire_dev);
printf("Terminating!\n");
fflush(stdout);