background serial corrupt bytes

geoff07

Senior Member
Is there any reason why the first two bytes received in the background after a reset might be corrupted? I have an 08M2 sending serial to a 28X2. The 08M2 sends
Code:
high HO_serial
pause 10 'high required for T polarity
serout HO_serial,T2400_4, ("Time:",#B_hrs,":",#B_mins,":",#B_secs,eot)
eot ($4) is an end of message marker. The 28X2 receives the data using hardware serial set up thus:
Code:
hsersetup B2400_64,%01001 'background receive, serout disabled, 'T' polarity
But the first two bytes of the first test message in the scratchpad after a power on reset read >uÚme:13:54:7< (the initial bytes are 117 and 218) rather than >Time:13:54:7<. Subsequent messages sent each second or so are received perfectly.

Is there some other initialisation required? The output serial line is already held high as advised. I'm rather at a loss as to why this might be. As two bytes are received in hardware I'm wondering if something is afoot in that area that needs attention. Obviously I could send a dummy message at startup but it would be nice to know the cause.
 

inglewoodpete

Senior Member
If the characters are received before or soon after changing the running clock of the 28X2, the Rx clock will not be 'synched' to the receive baud rate. Put a pause after the hSerSetup SetFreq command.
 
Last edited:

geoff07

Senior Member
Thanks for the comments. Yes I am using 64MHz. As it is a work-in-progress I will send the code to technical by email. When complete it will be a 28X2 driver for the 320x240 graphics displays you can get for a few dollars, allowing characters in several sizes and any filled or outline rectangle or circle in any colour using commands similar to those used by the RevEd oleds. The problem is in the area where the driver receives commands from the host program. When this is done the remainder will not take long to finish, as I think (hope) that all the hard bits are now complete. Then I will publish it.
 

Technical

Technical Support
Staff member
There are two possible problems - the 08M2 pin is still low (or floating low) when the 28X2 hsersetup is activated and so it gets spurious signals, or the setfreq has not settled - that just needs a pause.

A 4k7 pull up on the serial line may well help overcome reset noise. Or use N polarity at both ends instead, with a pull-down resistor.
 

geoff07

Senior Member
Thanks for the inputs, there has been some progress: the rtc i2c daughterboard (China special) that I am using on the 08 protoboard as the test host failed when I was preparing the files to send. As a result and to maintain progress I coded out the access to the DS1307 and just sent a constant message once per second, which worked every time with no corruption. So I suspect that the serial out was not sending correctly from the 08M2, which was powered from and thus restarted with the driver board.

The code below is the (messy) test program, where you can see the commented out part and its replacement. It was intended to send a time string once per second, but controlled by a CTS line from the driver chip (the graphics driver is too slow in writing pixels to allow uncontrolled messages, and I can only afford a few bytes for the buffer).

My problem is now solved, but it remains curious as to why an i2c transaction might interfere. The sertxd and serout messages were both affected so it looks like b12 (B_hrs) was corrupted.

On the subject of RTC modules, I bought some from a certain auction site, where they cost very little and came with a lithium CR2032. Two have so far failed, not yet investigated for cause but beware!
Code:
#picaxe 08M2
#no_data
#terminal 4800
symbol HO_led        = C.0
symbol HO_SCL        = C.1
symbol HO_SDA        = C.2
symbol HI_CTS        = pinC.3
symbol HO_serial     = C.4
symbol C_ds1307_addr = %11010000
symbol B_secs        = b10
symbol B_mins        = b11
symbol B_hrs         = b12
symbol B_day         = b13
symbol B_date        = b14
symbol B_month       = b15
symbol B_year        = b16
symbol B_control     = b17
symbol B_last_secs   = b18
symbol B_temp        = b19
symbol C_true        = 1
symbol eot           = 4 'ascii control code EOT CNTL-D
symbol C_false       = 0

sertxd("start0",cr,lf)

hi2csetup i2cmaster, C_ds1307_addr,i2cslow, i2cbyte
sertxd("start1",cr,lf)

'call set_time  'once only

sertxd("start3",cr,lf)
'replacement code
B_hrs = 10
B_mins = 30
B_secs = 0
do
   pause 1000
   inc B_secs
   B_secs = B_secs // 60
   do:loop until HI_CTS = C_true 
   high HO_serial
   pause 10 'required for T polarity
   serout HO_serial,T2400_4, ("Time:",#B_hrs,":",#B_mins,":",#B_secs,eot)
   sertxd("Time:",#B_hrs,":",#B_mins,":",#B_secs,cr,lf)
loop

#rem
'code for the DS1307 module, disabled due to faulty module
do 'send a string once whenever CTS goes high
   B_last_secs = B_secs
   do
      call read_time
   loop until B_secs <> B_last_secs 'wait for a new second
   'call flash_slow
   if HI_CTS = C_true then
      pause 10 'let the display get ready
      high HO_serial
      pause 10 'required for T polarity
      serout HO_serial,T2400_4, ("Time:",#B_hrs,":",#B_mins,":",#B_secs,eot)
      sertxd("Time:",#B_hrs,":",#B_mins,":",#B_secs,cr,lf)
   endif
loop 
#endrem
end
read_time:
   hi2cin 0,(B_secs,B_mins,B_hrs)  ',B_day,B_date, B_month,B_year,B_control)
   B_temp = B_secs AND %00001111 'units
   B_secs = B_secs / $F * 10 + B_temp 'plus tens
   'sertxd(#B_secs," ")
   B_temp = B_mins AND %00001111
   B_mins = B_mins / $F * 10 + B_temp
   B_temp = B_hrs  AND %00001111
   B_hrs  = B_hrs  / $F * 10 + B_temp
   return
set_time:
   B_secs    = %00000001
   B_mins    = %00100010
   B_hrs     = %00100000
   B_day     = 6
   B_date    = 8
   B_month   = %00010001 '11 -nov
   B_year    = %00010100 '14 -2014
   B_control = 0 'no square wave
   hi2cout 0,(B_secs,B_mins,B_hrs,B_day,B_date, B_month,B_year,B_control)
   return
 

inglewoodpete

Senior Member
I have to say I don't understand the fault that you are reporting.

One suggestion, though: move the "high HO_serial" command up into the initialisation code before the main loop. Then you can get rid of the "pause 10" command. Once the HO_serial pin has been set high, the serout pin will return it to that state after sending the text.
 

bpowell

Senior Member
I bought 5 pre-built DS1307 boards (about 5cm x 5cm) from ebay...male & female connectors, pull-up resistors you can enable or disable...clock and battery...I've had them for a couple of years now, still running great. How did your clock fail? What is it doing? Smoke? Quit ticking? Have you tried re-setting the time (and making sure the CH bit isn't set in the 0x00 address?)
 

geoff07

Senior Member
These are tiny boards only a little bigger than the battery. I haven't investigated yet. But they both return the same out of range value.
 
Top