Discussion:
[nuttx] singlewire communication can't work with stm32f103-minimum
niijyeni@yahoo.com [nuttx]
2018-03-19 02:47:22 UTC
Permalink
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);
'Juha Niskanen (Haltian)' juha.niskanen@haltian.com [nuttx]
2018-03-19 06:35:48 UTC
Permalink
Hello,


This forum has moved to Google groups, please post only there from now on.


You did not say what STM32 you are using. Some UART functionality might slightly differ between MCU models so you might have to fix stm32_1wire.c accordingly. Use debugger to check that the half-duplex loopback in UART works. Maybe your clocks are incorrect and that makes timeslots wrong too. Also check your GPIO_USART3_TX definition and board schematics around that pin, of course. From your supplied information, it is not possible to deduct if this is a SW or HW problem.


You are doing a Read-ROM operation, does it work any way differently if do Skip-ROM followed by triggering temp conversion by 0x44? You could try ONEWIRE_EXCHANGE(), does that make a difference? You need to use oscilloscope or logic analyzer to measure the pulses on wire and debug from there.


Best Regards,

Juha

________________________________
From: ***@yahoogroups.com <***@yahoogroups.com> on behalf of ***@yahoo.com [nuttx] <***@yahoogroups.com>
Sent: Monday, March 19, 2018 4:47:22 AM
To: ***@yahoogroups.com
Subject: [nuttx] singlewire communication can't work with stm32f103-minimum



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);

Loading...