I wrote a program in python that receive a binary number from Atmega32 (a microcontroller) 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);
}
Update : I change the programs in ATMEGA-side and Python-Side as suggested in the answers:
My AVR interrupt routine :
interrupt [EXT_INT0] void ext_int0_isr(void)
{
printf("%d",PINA);
printf("%d\n",0);
}
And this is my output in python :
>>> while(1):
ser.readline()
'35\n'
'135\n'
'135\n'
'135\n'
'135\n'
'135\n'
'135\n'
'agi\x16agi\x16\xff135255\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'1350\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'1350\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'1350\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
'135255\n'
'1350\n'
'135255\n'
As you see, the output is not that we expected from the AVR code and Python code!