one-wire on UART

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

WaL
Posts: 6
Joined: Tue May 15, 2018 11:52 am
Has thanked: 1 time

one-wire on UART

Postby WaL » Tue May 15, 2018 12:10 pm

Hello! I'm just starting to program and I do not understand much :oops:
The task was to read the code from DS1990
I tried to do this on UART, but nothing comes out
I can send a reset signal and get a response from DS1990. I did it on USART and on UART, for example:

halconf.h

Code: Select all

#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
#define SERIAL_DEFAULT_BITRATE    9600
#endif


main:

Code: Select all

sdStart(&SD1, NULL);
  ////
  uint8_t reset_onewire=0xF0;
  uint8_t readrom[8]={0x00,0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF};
  while(1)
  {
    sdWrite(&SD1, reset_onewire,1);
    chThdSleepMilliseconds(500);
  }


I connected the terminal to the UART and watch the result there.
If DS1990 is connected, then I get the answer E0, and if not, then F0

But the next command should be sent at 115200 baud rate. And I do not know how to change the transmission speed quickly, since if you restart the serial driver from a different configuration it takes a long time
Maybe I'll do it completely wrong?

I hope you understand my English, since I used Google Translate :lol:
I use STM32F103C8T6 ( BLUEPILL board)

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: one-wire on UART

Postby Giovanni » Tue May 15, 2018 12:28 pm

Hi,

This forum is not for support, you should post in the STM32 section.

Make sure your output pin is assigned to UART, by default pins are GPIO, see your board.h.

Giovanni

WaL
Posts: 6
Joined: Tue May 15, 2018 11:52 am
Has thanked: 1 time

Re: one-wire on UART

Postby WaL » Tue May 15, 2018 2:36 pm

Thanks! My code:

Code: Select all

#define GPIOA_USART1_TX         9       
#define GPIOA_USART1_RX         10 

and

Code: Select all

#define VAL_GPIOACRH            0x888884B8      /* PA15...PA8 */


But as such, UART transmission works. The question is how to change the baud rate without restarting the driver, since it takes a long time to restart it!

Maybe I do not understand how to implement a 1-wire interface. But if you believe these images, you need to transfer data at different baud rates
Image
Image

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: one-wire on UART

Postby Giovanni » Tue May 15, 2018 2:56 pm

Hi,

Changing speed is done using sdStart() again (without calling sdStop()), note that if you call it again the execution time is much smaller because just the UART is reinitialized.

Giovanni

WaL
Posts: 6
Joined: Tue May 15, 2018 11:52 am
Has thanked: 1 time

Re: one-wire on UART

Postby WaL » Tue May 15, 2018 8:10 pm

Yes, it really works, thanks!
But for some reason the sensor still does not answer me!
I send him the following data but I do not get a response

Code: Select all

static SerialConfig uartCfg1 =
    {
    9600, // bit rate
    };
  static SerialConfig uartCfg2 =
      {
      115200, // bit rate
      };

  uint8_t reset_onewire=0xF0;
  uint8_t readrom_cmd[8]={0x00,0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF};
  uint8_t readrom[8]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  while(1)
  {
    sdStart(&SD1, &uartCfg1);
    sdWrite(&SD1, &reset_onewire,1);

    sdStart(&SD1, &uartCfg2);
    sdWrite(&SD1, &readrom_cmd,8);

    for (int i=0; i<8;i++)
    {
      sdWrite(&SD1, &readrom,8);
    }


The terminal shows 64 bits of FF.

WaL
Posts: 6
Joined: Tue May 15, 2018 11:52 am
Has thanked: 1 time

Re: one-wire on UART

Postby WaL » Tue May 15, 2018 8:18 pm

In fact, it seems that the first byte at 9600 baud does not have time to be transmitted in this case

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: one-wire on UART

Postby steved » Tue May 15, 2018 10:54 pm

You have to wait until the transmitter shift register is empty before changing the speed.
Use the TxEnd2 callback to signal this point and set a flag, then change the baud rate.

Incidentally, while using a UART for this is perfectly possible, it is common to either 'bit-bang' the interface, or use an interface chip such as the DS2484 to help. (The latter deals with all of the timing and line drive issues)

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: one-wire on UART

Postby rew » Tue May 22, 2018 6:19 pm

Guys,
that chip talks a protocol called "onewire". The chibios codes seem to hint that you're trying to use the USART for communicating with this thing. That's not going to work, just like that. I vaguely remember that a trick was possible, by tying the RX and TX lines together, but I don't remember how that was done.

In any case, the chip will transmit a bit after you've asked it to send the next one, So things are not as simple as requesting something and then just waiting for the bits to come in.

I would recommend that you look for a "one wire library", instead of messing with the serial port driver.

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: one-wire on UART

Postby rew » Sun May 27, 2018 7:17 pm

I think I remember now: You wire the RX and the TX of the uart together. Configure the TX pin not as the normal "push-pull" but as opendrain. Now you send an "0xff" at the correct baud rate, and the one-wire device will be able to send you a single bit. It will keep the dataline pulled low for a few bit-periods to send a 0 and it will return the line to high asap for a 1. Now by checking the RX byte, you can figure out how long the device kept the line low. If you get 0x00, obviously that was 8 bit times. and a zero. But it won't keep it low that long so you'll see 0x01, 0x03, ... when you recieve a "0" bit.

faisal
Posts: 374
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 44 times
Been thanked: 60 times

Re: one-wire on UART

Postby faisal » Sun May 27, 2018 7:48 pm



Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 19 guests