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.

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.

  • Oh, thanks. I did not think that it was a string "1". – Berd Oct 27 '17 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.