one-wire on UART

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

Moderators: barthess, RoccoMarco

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: 10823
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 318 times
Been thanked: 268 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: 10823
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 318 times
Been thanked: 268 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: 512
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 3 times
Been thanked: 47 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: 232
Joined: Sat Jul 19, 2014 12:59 pm
Been thanked: 3 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.


Return to “STM32 Support”

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests