diff --git a/bacnet-stack/ports/atmega168/bacnet.aps b/bacnet-stack/ports/atmega168/bacnet.aps
index 4486921e..b55ef2a5 100644
--- a/bacnet-stack/ports/atmega168/bacnet.aps
+++ b/bacnet-stack/ports/atmega168/bacnet.aps
@@ -1 +1 @@
-13-Aug-2007 15:08:2714-Aug-2007 17:09:10013-Aug-2007 15:08:2744, 13, 0, 528AVR GCC241bacnet13-Aug-2007 15:11:0713-Aug-2007 15:11:07241013-Aug-2007 15:11:0744, 13, 0, 528AVR GCCdefault\bacnet.elfC:\code\bacnet-stack\ports\atmega168\falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31AVR SimulatorAVR SimulatorATmega168.xmlAuto000main.crs485.ctimer.cavr035.hhardware.hrs485.hiocompat.htimer.hdefaultNOatmega16810
bacnet.elfdefault\0..\..\-Wall -gdwarf-2 -DF_CPU=7372800UL -O0 -fsigned-chardefault1C:\WinAVR-20070525\bin\avr-gcc.exeC:\WinAVR-20070525\utils\bin\make.exe00000C:\WinAVR-20070525\avr\include\avr\eeprom.h100001C:\WinAVR-20070525\avr\include\avr\iomx8.h100002C:\WinAVR-20070525\examples\stdiodemo\uart.h100003C:\WinAVR-20070525\examples\stdiodemo\uart.c100004main.c100005timer.c259748 696 908 72020 45566 211 1235 650690 21428 696 588 7200 0268 696 428 7200 0444 272 1300 69850 14290 118 1092 52052 2
+13-Aug-2007 15:08:2715-Aug-2007 11:27:19013-Aug-2007 15:08:2744, 13, 0, 528AVR GCC241bacnet13-Aug-2007 15:11:0713-Aug-2007 15:11:07241013-Aug-2007 15:11:0744, 13, 0, 528AVR GCCdefault\bacnet.elfC:\code\bacnet-stack\ports\atmega168\ATmega168falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31AVR SimulatorAVR SimulatorATmega168.xmlAuto000main.crs485.ctimer.cavr035.hhardware.hrs485.htimer.hdefaultNOatmega16810
bacnet.elfdefault\1..\..\-Wall -gdwarf-2 -DF_CPU=7372800UL -O0 -fsigned-chardefault1C:\WinAVR-20070525\bin\avr-gcc.exeC:\WinAVR-20070525\utils\bin\make.exe028216193737280001100000C:\WinAVR-20070525\avr\include\avr\eeprom.h100001C:\WinAVR-20070525\avr\include\avr\iomx8.h100002C:\WinAVR-20070525\examples\stdiodemo\uart.h100003C:\WinAVR-20070525\examples\stdiodemo\uart.c100004main.c25900005timer.c25900006rs485.c25700007hardware.h100008C:\WinAVR-20070525\avr\include\avr\interrupt.h1429 695 589 7190 0269 97 1069 497670 23589 695 749 7190 0269 695 429 7190 0313 141 1113 54185 13335 163 1135 56338 26291 119 1091 5190 0357 185 1157 58532 27445 273 1245 697101 0
diff --git a/bacnet-stack/ports/atmega168/main.c b/bacnet-stack/ports/atmega168/main.c
index 29f8c54b..4046c905 100644
--- a/bacnet-stack/ports/atmega168/main.c
+++ b/bacnet-stack/ports/atmega168/main.c
@@ -50,7 +50,9 @@ void init(void)
DDRD = 0;
PORTD = 0;
- /* Configure the watchdog timer */
+ /* Configure the watchdog timer - Disabled for testing */
+ BIT_CLEAR(MCUSR,WDRF);
+ WDTCSR = 0;
/* Configure USART */
RS485_Set_Baud_Rate(38400);
diff --git a/bacnet-stack/ports/atmega168/rs485.c b/bacnet-stack/ports/atmega168/rs485.c
index 4721717b..58d47b84 100644
--- a/bacnet-stack/ports/atmega168/rs485.c
+++ b/bacnet-stack/ports/atmega168/rs485.c
@@ -51,8 +51,16 @@ void RS485_Initialize(void)
/* enable Transmit and Receive */
UCSR0B = _BV(TXEN0) | _BV(RXEN0);
- /* Set frame format: 8data, 2stop bit */
- UCSR0C = _BV(USBS0) | _BV(UCSZ00);
+ /* Set USART Control and Status Register n C */
+ /* Asynchronous USART 8-bit data, No parity, 1 stop */
+ /* Set USART Mode Select: UMSELn1 UMSELn0 = 00 for Asynchronous USART */
+ /* Set Parity Mode: UPMn1 UPMn0 = 00 for Parity Disabled */
+ /* Set Stop Bit Select: USBSn = 0 for 1 stop bit */
+ /* Set Character Size: UCSZn2 UCSZn1 UCSZn0 = 011 for 8-bit */
+ /* Clock Polarity: UCPOLn = 0 when asynchronous mode is used. */
+ UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
+ /* Clear Power Reduction USART0 */
+ BIT_CLEAR(PRR,PRUSART0);
return;
}
@@ -131,13 +139,14 @@ void RS485_Send_Frame(
UDR0 = *buffer;
buffer++;
nbytes--;
- /* per MSTP spec */
- if (mstp_port) {
- mstp_port->SilenceTimer = 0;
- }
}
- while (!BIT_CHECK(UCSR0A,UDRE0)) {
- /* do nothing - wait until Tx buffer is empty */
+ while (!BIT_CHECK(UCSR0A,TXC0)) {
+ /* do nothing - wait until the entire frame in the
+ Transmit Shift Register has been shifted out */
+ }
+ /* per MSTP spec */
+ if (mstp_port) {
+ mstp_port->SilenceTimer = 0;
}
return;
@@ -151,8 +160,16 @@ void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
}
/* wait for state machine to read from the DataRegister */
else if (mstp_port->DataAvailable == false) {
+ /* check for error */
+ if (BIT_CHECK(UCSR0A,FE0)) {
+ mstp_port->ReceiveError = true;
+ }
+
+ if (BIT_CHECK(UCSR0A,DOR0)) {
+ mstp_port->ReceiveError = true;
+ }
/* check for data */
- if (!BIT_CHECK(UCSR0A,RXC0)) {
+ if (BIT_CHECK(UCSR0A,RXC0)) {
mstp_port->DataRegister = UDR0;
mstp_port->DataAvailable = true;
}
diff --git a/bacnet-stack/ports/atmega168/timer.c b/bacnet-stack/ports/atmega168/timer.c
index 63469c54..c4c6d572 100644
--- a/bacnet-stack/ports/atmega168/timer.c
+++ b/bacnet-stack/ports/atmega168/timer.c
@@ -46,6 +46,8 @@ void timer_initialize(void)
TCNT1 = TIMER_1_COUNT;
/* Enable the overflow interrupt */
BIT_SET(TIMSK1,TOIE1);
+ /* Clear the Power Reduction Timer/Counter0 */
+ BIT_CLEAR(PRR,PRTIM1);
}