I need some help. I had to create a new serial for my motherboard. I decided to emulate a serial via bit bang. The code is below. I am finding problem in my code sync bit bang with a traditional RS232 code. The mainboard is generating the signal correctly, but the receiver can not identify the number sent correctly.

#include &lt;avr/io.h&gt;
#include "bit_bang.h"
#include &lt;util\delay.h&gt;
#define tx_pin_high() PORTB |= (1&lt;&lt;7)
#define tx_pin_low() PORTB &amp;= ~(1&lt;&lt;7)



void init_port_bit_bag()
{

    DDRB = 0xFF; 
    PORTB  = 0x00; 
}

void uart_tx_bit_bang_8bit(unsigned char data)
{

    unsigned int i = 0;
    tx_pin_low();

    _delay_us(2);

    for( i=8 ; i!=0 ; --i) //LSB BIT
    {
        if(data &amp; 0x01) 
        {
            tx_pin_high(); 
        }
        else 
        {
            tx_pin_low(); 
        }

        data &gt;&gt;= 1;
        _delay_us(156);
    }

    tx_pin_high();
    _delay_us(2);
}


I have tested this code and it is working perfectly. The loop to generate the word is spending 625.25us sent per byte, thus achieving almost ideal to have the 9600 bps. What I need is to synchronize this code with a serial RS 232 traditional or create a serial bit bang receiving. I performed some tests using traditional functions of RS 232 and folow the code below, the received is different from what is being sent. Can anyone help me please? The serial data receiver is picking up different than what I'm sending.

char uart_getchar (void)
{
    while (!(UCSRA &amp; (1 &lt;&lt; RXC)));
    return UDR;
}

while (1)
{          
           rx = uart_getchar();
           _delay_ms(30);

            uart_string("Information:");
        uart_putchar('\n');
        uart_putchar((rx/10)%10+'0');
        uart_putchar(rx%10+'0');
        uart_putchar('\n');
        _delay_ms(1000);
}


That's what I'm sent.

#include &lt;avr\io.h&gt;
#include &lt;avr\interrupt.h&gt;
#include &lt;util\delay.h&gt;
#include "bit_bang.h"

int main(void)
{   
    char date1 = 6;   

    init_port_bit_bag();
    while (1)
    {
    uart_tx_bit_bang_8bit(date1);
    _delay_ms(10);
    }
}


And I'm getting the numbers 7, 14, 15,17. I think the error is in the synchronization of start bit.


Question: Simpler method to show $k(x)$ is NOT a primitive irreducible polynomial?
Answer: A quadratic polynomial $k(x)\in\Bbb{Z}_{11}[x]$ is primitive, iff the (multiplicative) order of the coset
$$
\alpha=x+\langle k(x)\rangle
$$
in the field $\Bbb{Z}_{11}[x]/\langle k(x)\rangle=\Bbb{F}_{121}$ is $120$. By Lagrange's theorem the order is always a factor of $120$. Thus it is one of $\{1,2,3,4,5,6,8,10,12,15,20,24,30,40,60,120\}$. To speed up checking you can furthermore make the  observation that if $\alpha^{120/p}\neq1$ for all prime factors $p$ of $120$ (s0 $p=2,3$ or $5$), then the order has to be maximal, i.e. $\alpha$ is a primitive element (or $k(x)$ is a primitive polynomial). Of course, it may turn out that $\alpha$ is not primitive, in which case you will see evidence of this at some point.

In this task square-and-multiply is your friend. Do remember to use the equation
$$
k(\alpha)=0\Longleftrightarrow\alpha^2=-(2\alpha+2)=9\alpha+9
$$
in each step.
For example
$$
\begin{array}{rll}
\alpha^2&amp;=&amp;=-(2\alpha+2)\\
\alpha^4&amp;=(\alpha^2)^2=(2\alpha+2)^2=4\alpha^2+8\alpha+4&amp;=7
\end{array}
$$
I stop here, because we see that something slightly unexpected happened: $\alpha^4$ belongs to the prime field $\Bbb{Z}_{11}$. At this point I reveal that you can answer the question about primitivity simply by calculating the order of $7$ in the prime field. Leaving that to you!

With 20/20 hindsight we can see that the result about $\alpha^4$ is a consequence of the factorization (in $\Bbb{Z}_{11}[x]$ or actually already in $\Bbb{Z}[x]$)
$$
x^4+4=(x^4+4x^2+4)-4x^2=(x^2+2)^2-(2x)^2=(x^2+2x+2)(x^2-2x+2)
$$
showing that $k(x)$ is a factor of $x^4+4=x^4-7$.