LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   serial port (and baud-rate) problem (https://www.linuxquestions.org/questions/linux-newbie-8/serial-port-and-baud-rate-problem-571877/)

kafix 07-24-2007 08:58 AM

Serial port: write single bit (Updated)
 
(See update below)

Hi!

I'm trying to get a serial device working on my linux (debian) system. On the internet, I found these rules for the communication:

Quote:

  • Transmit a break time, which is a logical "0" lasting for 88 microseconds. On a microcontroller you can usually do this by temporarily setting the baud rate to 96KBaud, then transmit a "0" byte.
  • Then transmit a startcode of "0" (returning the baud rate to 250KBaud).
  • Then transmit up to 512 8-bit channel level bytes
Source: sabretechnology.co.uk/dmxwork.htm
Now I'm not quite sure how to implement that. My version:

Code:

stty -F /dev/ttyS0 96000
echo 0 > /dev/ttyS0
stty -F /dev/ttyS0 250000
echo  0ggg > /dev/ttyS0

Now, that doesn't work. (The device's data-LED is on when I run the script.) With stty I couldn't set the baud-rates to the 96k and 250k as written in the specifications (Error message: stty: invalid argument ,,96000"). BTW: Changing to 9600 and others does work!

How would you implement these specifications?
Could anybody help me, please?

kafi


(Sorry for my english)

UPDATE 07-24-07 06:02 PM
Ok I think I could fix the baud-problems on my own. But now I should write single bits to the serial port. Is this possible using bash?

Wim Sturkenboom 07-24-2007 11:00 AM

I assume that the following is (one of) your problem(s):
The 0 that you tranmit is the character 0 (30h) and not 00h.

You can try \x00 instead of 0, but I'm not that familiar with bash scripting to give you a garantee about the correctness.

kafix 07-24-2007 11:24 AM

Thanks for your reply! I don't see any changes yet, but I agree that your \x00 is likely to be more correct that just 0. Thanks for your hint!

kafi

kafix 07-24-2007 06:07 PM

Ok I think I could fix the baud-problems on my own. But now I should write single bits to the serial port. Is this possible using bash?

cu kafi

dxqcanada 07-24-2007 06:21 PM

In terms of RS232 serial communications ...

a logical 0 is a positive voltage state
a logical 1 is a negative voltage state

By sending any data through the serial UART you are creating voltage transitions that reflect the data bits being sent.

It sounds like you are trying to induce a serial break.
A serial break signal is a logical 0 (positive voltage) for longer than a character length.

Wim Sturkenboom 07-25-2007 12:11 AM

What do you mean by 'write single bits'? The uart will always output a specified number of bits. Usually it's 7 or 8, but 5 is possible as well (if I remember correctly it's the lowest that I have seen).

dxqcanada 07-25-2007 05:32 PM

You cannot create a hardware break by sending data.

The break (logical 0) must span longer than a character length.

Example ... minicom can perform such an action.

How you do this in a shell script ??

I do not think the shell has ability to do this.
Other programing languages have a serial library that can do this such as C ... or possibly perl.

Wim Sturkenboom 07-25-2007 10:31 PM

As described in opening post, I think one can by changing the baudrate to a lower value and transmitting the 'break'. The receiving end will not change the baudrate, so it will see a longer logical 0.

dxqcanada 07-26-2007 04:54 PM

Quote:

Originally Posted by Wim Sturkenboom
As described in opening post, I think one can by changing the baudrate to a lower value and transmitting the 'break'. The receiving end will not change the baudrate, so it will see a longer logical 0.

Ahh, I get it ...
Open the TTY, then drop the /dev/ttyS0 speed lower than the serial devices speed ... then send a null (\x00) ... and the output character will be logical 0 and the lower baud rate will make it appear to the serial device as being longer than it's expected character length (then flip the/dev/ttyS0 back to normal speed).


All times are GMT -5. The time now is 11:17 AM.