I wrote a program in python2.7 that receive a binary number from Atmega32 via USART and prints it in output.
in the other hand, My Atmega32 read its PINA on the interrupt firing and sends its value to the computer using USART.
this is my python program :
>>> import serial >>> ser=serial.Serial ('COM3') >>> ser.open() >>> while(1): ser.read()
when I connect PINA pins in a way that make00000111 (equal to 7), I see the below output in python:
'7' '7' '7' '7' '7' '7' . . .
But when I connect PINA pins in a way that make 10000111 (equal to 135), I see the below output in python :
'1' '3' '5' '1' '3' '5' '1' '3' '5' '1' '3' '5' '1' '3' '5' '1' '3' '5' . . .
As you see above, it prints 135 in three line! Why?
FYI : This is the program that I wrote for Atmega32 in CodeVision :
interrupt [EXT_INT0] void ext_int0_isr(void) { printf("%d",PINA); }
As I can't distinguish a multi-digit number from some singl-digit numbers (for example, I can't distiguish 135 from 1, 3 and 5 in a row), I change my Codevision program as below :
interrupt [EXT_INT0] void ext_int0_isr(void) { printf("%d",PINA); printf("$$$$"); }
I expect an output like below (for PINA='00000111') :
7 $ $ $ $ 7 $ $ $ $ 7 $ $ $ $ 7
and for PINA='10000111' I expect the below output :
1 3 5 $ $ $ $ 1 3 5 $ $ $ $ 1 3 5 $ $ $ $
But, what I received is like below :
7 $ $ $ $ 7 $ $ $ $ 7 $ $ $ $ 7 7 7 $ $ $ $ 7 $ $ $ $ 7 7 7 $ $ $ $ 7 $ $ $ $ 7 7 7 $ $ $ $
and
1 3 5 $ $ $ $ 1 3 5 $ $ $ $ 1 3 5 $ $ $ $ 1 3 5 $ $ $ $ 1 3 5 1 3 5 1 3 5 $ $ $ $ 1 3 5 1 3 5 1 3 5 $ $ $ $ 1 3 5 1 3 5 1 3 5 $ $ $ $ 1 3 5
As you see in the real outputs above, sometimes 7 repeated unexpectedly before printing dollar signs!
So, I have two questions:
1- Why python prints a single multi-digit number in multiple lines? (while 135 is one byte and we expect it to print each byte in a singe line)!
2- Why in the second form of interrupt routine, PINA value repeats unexpectedly for 3 times between printing $ sings? (Can it be related to the speed of interrupt firing rate?)