Hallo all, pleas i need help with mein project with ATMEGA64. I need read and write data in Serport1 and Serport2.
I write basic testing program for reading and send data.
Serport1 work good (No problem) but Serport2 is absolutly 'death' .
I dont know why!
I triyng change the MCU for new and Serport2 still not work
Max232 on serport2 is ok and testing with serport1 and work good. Where is problem?
Any idea?
here is my basic code...
----------------------------------------------------------------------------------------------------------------------------
program test_serial;
{ $BOOTRST $07000} {Reset Jump to $07000}
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = mega64, VCC=5;
Import SysTick, SerPort, SerPort2;
From System Import ;
Define
ProcClock = 16000000; {Hertz}
SysTick = 10; {msec}
StackSize = $0064, iData;
FrameSize = $0064, iData;
SerPort = 19200, Stop1; {Baud, StopBits|Parity}
RxBuffer = 16, iData;
TxBuffer = 16, iData;
SerPort2 = 19200, Stop1; {Baud, StopBits|Parity}
RxBuffer2 = 16, iData;
TxBuffer2 = 16, iData;
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
Led_TX [@PortD, 5] : Bit;
Led_RX [@PortD, 4] : Bit;
ZnakIn : Array [0..20] of byte;
InCykl : byte;
Led_Rxcount : Integer;
Led_Txcount : Integer;
{--------------------------------------------------------------}
{ functions }
interrupt RXRDY;
begin
ZnakIn[InCykl] := SerInp;
if ZnakIn[0] = $31 then
InCykl := InCykl + 1;
else
InCykl := 0;
endif;
end;
procedure InitPorts;
begin
DDRD := %00110000;
end InitPorts;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
InitPorts;
EnableInts;
loop
if InCykl >= 18 then
InCykl := 0;
ZnakIn[0] := 0;
Led_Rx := True;
Write( SerOut, 'Test Port 1' );
Write( SerOut2, 'Test Port 2' );
FlushBuffer ( TxBuffer );
FlushBuffer ( TxBuffer2 );
Led_Tx := True;
endif;
If (Led_rx = true) then Inc(Led_Rxcount); else Led_Rxcount := 0; endif;
If (Led_Rxcount >= 50) then Led_Rx := false; Led_Rxcount := 0; endif;
If (Led_tx = true) then Inc(Led_Txcount); else Led_Txcount := 0; endif;
If (Led_Txcount >= 50) then Led_Tx := false; Led_Txcount := 0; endif;
mdelay(1);
endloop;
end test_serial.
Thanks for your time.
I write basic testing program for reading and send data.
Serport1 work good (No problem) but Serport2 is absolutly 'death' .
I dont know why!
I triyng change the MCU for new and Serport2 still not work
Max232 on serport2 is ok and testing with serport1 and work good. Where is problem?
Any idea?
here is my basic code...
----------------------------------------------------------------------------------------------------------------------------
program test_serial;
{ $BOOTRST $07000} {Reset Jump to $07000}
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = mega64, VCC=5;
Import SysTick, SerPort, SerPort2;
From System Import ;
Define
ProcClock = 16000000; {Hertz}
SysTick = 10; {msec}
StackSize = $0064, iData;
FrameSize = $0064, iData;
SerPort = 19200, Stop1; {Baud, StopBits|Parity}
RxBuffer = 16, iData;
TxBuffer = 16, iData;
SerPort2 = 19200, Stop1; {Baud, StopBits|Parity}
RxBuffer2 = 16, iData;
TxBuffer2 = 16, iData;
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
Led_TX [@PortD, 5] : Bit;
Led_RX [@PortD, 4] : Bit;
ZnakIn : Array [0..20] of byte;
InCykl : byte;
Led_Rxcount : Integer;
Led_Txcount : Integer;
{--------------------------------------------------------------}
{ functions }
interrupt RXRDY;
begin
ZnakIn[InCykl] := SerInp;
if ZnakIn[0] = $31 then
InCykl := InCykl + 1;
else
InCykl := 0;
endif;
end;
procedure InitPorts;
begin
DDRD := %00110000;
end InitPorts;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
InitPorts;
EnableInts;
loop
if InCykl >= 18 then
InCykl := 0;
ZnakIn[0] := 0;
Led_Rx := True;
Write( SerOut, 'Test Port 1' );
Write( SerOut2, 'Test Port 2' );
FlushBuffer ( TxBuffer );
FlushBuffer ( TxBuffer2 );
Led_Tx := True;
endif;
If (Led_rx = true) then Inc(Led_Rxcount); else Led_Rxcount := 0; endif;
If (Led_Rxcount >= 50) then Led_Rx := false; Led_Rxcount := 0; endif;
If (Led_tx = true) then Inc(Led_Txcount); else Led_Txcount := 0; endif;
If (Led_Txcount >= 50) then Led_Tx := false; Led_Txcount := 0; endif;
mdelay(1);
endloop;
end test_serial.
Thanks for your time.