7

I have been trying to learn more about bit transmission through the uart, and I have the following code in python to transmit information:

import serial

ser = serial.Serial(

    port='/dev/ttyAMA0',
    baudrate = 1000000,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)

b=1

ser.write(b)

I then connected an oscilloscope to the Tx line. I get the following waveform:

Which 1us=1bit. I can clearly see that the least significant bit comes first, and I can see the start and stop bits, however, why are there two 1s in the middle of the sequence? Shouldn't it be 00000001?

Thanks in advance.

Helder Esteves
  • 217
  • 2
  • 6

1 Answers1

11

To me it looks like ser.write(1) has an implicit conversion to string. So your 1 becomes a "1" which is 00110001, which perfectly fits into your observation.

user49015
  • 2,712
  • 17
  • 23