NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » [LED ARRAY MOD HELP] Adding Even Parity

March 23, 2011
by wArri
wArri's Avatar


Me and some friends wanted to see if we could modify the that comes with the led_array kit code, to transmitt even parity, as well as modify the uart.c to recieve in even parity. (Then later on we can send a wrong bit stream, and check the error flag register to be notified of an error)

We started by modifying the python script to initialize the serial connection with even parity as follow

serial_comm_dev = "COM5"
serial_comm_rate = 115200
query_socket_port = 7777
parity= serial.PARITY_EVEN

serial = serial.Serial(serial_comm_dev, serial_comm_rate, parity=parity)
scrollMode = True
buffer = []

Then we modified the uart.c to initalize with even parity as well by doing the following:

void uart_init() {

      // set baud rate
      UBRR0H = 0;
      UBRR0L = 7;   // for 115200bps with 14.7456MHz clock
      // enable uart RX and TX
      UCSR0B = (1<<RXEN0)|(1<<TXEN0);
      // set 8E1 frame format
      UCSR0C = (1<<UCSZ01)|(1<<UCSZ00)|(1<<UPM01);

      // set up STDIO handlers so you can use printf, etc
      fdevopen(&uart_putchar, &uart_getchar);

When we flash to the board, and run the python script, we no-longer can display anything on the array.

Are we missing something in initialization? Are we doing it wrong?



March 25, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi wArri,

I see nothing wrong in your initialization, and from what I see it should work. My current thought is that PySerial might not actually be sending the parity bit correctly. If you take a look at the documentation it it does say "Enable parity bit checking" on the parameter description, and mentions nothing about generating the bit. It would be very odd for the module not to be doing that correctly, but its possible.

There are unused bits in each byte that is sent as part of every character, you could add your own error detection in those bits.


Post a Reply

Please log in to post a reply.

Did you know that a NerdKit can take control of a remote-controlled car? Learn more...