For some time I have had 'troubles' with a serial port that gets 4000-5000 bytes of data from a noise meter. Data rate is slow, and from time to time the processor resets. Today i wrote some test code, as shown below. Whenever the push button is pressed momentarily, the noise meter gets a few setup bytes, and then sends 4008 characters to the uP. The noise meter has RTS/CTS which are hooked up via a MAX202 RS232 transceiver. If I look at the data with a PC using HT, it behaves and looks exactly as one would expect. No roque char, no pauses or anything untoward. Turning brownout off has no effect. All testing has been done with WD off[code:1:968df1b884]
'*******************************************************************************
$PROG &HFF , &HD7 , &HD8 , &HFC ' with brownout.
'*******************************************************************************
$regfile = "m1284pdef.dat"
$crystal = 9830400
'*****************************************************************************
$framesize = 500 ' Located at top of 16k of SRAM
$hwstack = 500 '
$swstack = 500 '
Disable Jtag
'-------------------------------------------------------------------------------
'Open a software UART TRANSMIT channel for debug dB9
Open "comc.3:9600,8,n,1" For Output As #1 '
Open "comc.2:9600,8,n,1" For Input As #5
'--------------------------------------------------
'Open Hardware uart on pins 14 & 15 for NOR140
'com 1
' CTS is an input ( on the uart)
' RTS is an output ( on the uart)
$baud = 9600
Open "com1:" For Binary As #3 'Nor140
Config Serialin = Buffered , Size = 250 , Cts = Pind.4 , Rts = Pinc.5 , Threshold_full = 50 , Threshold_empty = 50
'Threshold_full is bufspace at which data flow stops, controlled by RTS.
'Threshold-empty is no of bytes from the top of the buffer size at which flow is enabled again.
'probably they should both be about the same number
Config Serialout = Buffered , Size = 250
enable interrupts
Dim Rxbyte As Byte 'byte received from modem or sound meter
Dim N As Integer
dim charcount as integer
dim inarr(10) as byte '10 byte inwards array
Pa4led Alias Porta.4
Config Pa4led = Output
Pc4led Alias Portc.4
Config Pc4led = Output
Pd7led Alias Portd.7
Config Pd7led = Output
Testpb Alias Pinb.3
Config Testpb = Input 'test push button
Portb.3 = 1 'Pullup On
'------------------------------------------------
Print #1 , ">> Cpu Startup - MCUSR = " ; Mcusr
Select Case Mcusr
Case Is = 16
Print #1 , ">> JTAG RESET"
Case Is = 8
Print #1 , ">> Watchdog reset"
Case Is = 4
Print #1 , ">> Brownout reset"
Case Is = 2
Print #1 , ">> External reset"
Case Is = 1
Print #1 , ">> Power on reset"
Case Is = 0
Print #1 , ">> power-on reset flag"
End Select
Mcusr = 0 'set all flags to 0
Config Watchdog = 8192 ' 8secs does work with the 1284P
' Start Watchdog
stop watchdog
print #1 , "start of my loop"
'******************************************************************
do
print #1 , "wait " ;
wait 5
stop watchdog
If Testpb = 0 Then 'start the data flow
charcount = 0
Print #3 , "xc1;" 'select transfer F data
Print #3 , "xw0;" 'select A weighting
print #1 , "data coming"
print #3 , "ub0,500;it;" 'initiate 500 blocks x 8bytes bytes of data terminated by "Nor140"
end if
waitms 100 'wait for first few bytes
while ischarwaiting(#3) <> 0
if pinc.5 = 1 then 'monitor RTS
set pc4led
else
reset pc4led
end if
rxbyte = inkey(#3) ;
print #1 , chr(rxbyte);
' waitus 5000
incr charcount
for n = 1 to 5
inarr(n) = inarr(n + 1) 'shuffle the array
next
inarr(6) = rxbyte
' look for end of the data
dim instring as string * 6 at inarr(1) overlay
if instring = "Nor140" then
print #1 , " got eos"
exit while
end if
wend
print #1 , "charcount= " ; charcount
loop
'******************************************************************************
[/code:1:968df1b884]
Most of the time, pushing the button gets the correct response.[quote:968df1b884]
data coming
.
.
etc.
E 52.1
E 40.5
E 51.8
E 39.7
Nor140 got eos
charcount= 4008[/quote:968df1b884]
However every now and again, the processor resets thus: [quote:968df1b884]
data coming
.
.
etc.
.
.
E 42.4
E 48.3
E 40.0
E 40.4
E 39.3
E 39.3
E 39.6
E 39.1
E 39.2
up - MCUSR = 0
>> power-on reset flag
start of my loop
wait[/quote:968df1b884]
I have spent several ( read many!) hours trying to find out why. The led on PA4 never flashes unless I put a delay in the receive loop, which slows it down enough for the serial buffer to fill. The crashes do not seem to be related to this, and if I look at bufspace, the buffer cycles between 45 bytes and 200 bytes, which is correct given the setting of 250 buffer size, and limits 50 from the bottom and 50 from the top.
In spite of what MCUSR says, it is not a power supply problem. The board is running from a 12v 50AHr battery, with a 7805 regulator, and several 1000 uF around the board. With no serial data the board will run for weeks at a time without a reset. Its almost like the processor stumbles or chokes on the incoming RS232 data. If I take out the array end of string stuff, it makes no difference.
[b:968df1b884][color=red:968df1b884](BASCOM-AVR version : 2.0.7.6 )[/b:968df1b884][/color:968df1b884]
↧