08M2 serout corrupt and restarts after serin

I'm trying to use the serial terminal to get a 08M2 to relay commands to an I2C device but it wasn't transmitting anything so to troubleshoot I'm trying to output the exact data it received back to the terminal and the data the 08M2 transmits is completely unexpected and makes no sense.
I'm also decoding the serial data with a Picoscope to verify the data.

This is the program:
Code:
;C.0 = display out
;C.1 = I2C SCL
;C.2 = I2C SDA
;C.3 = button
;C.4 =
;C.5 =
#picaxe 08M2
high C.0
pause 2000
setfreq m32
;pullup %00001110
symbol baud=T38400_32
serout C.0,baud,(128)
pause 1
serout C.0,baud,("DAC ")
pause 12
serout C.0,baud,(192)
pause 1
serout C.0,baud,("DAC ")
pause 12
main:
serin C.5,N38400_32,b0,b1,b2
pause 4000
serout C.0,baud,(128)
pause 1
serout C.0,baud,("DAC ",b0,b1,b2)
pause 12
;hi2csetup i2cmaster, b0, i2cfast_32, i2cbyte
;hi2cout b1, (b2)
goto main
I'm trying to send it 36,1,1 in the terminal and it sends back:

Code:
000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 128
128 000 128 000 128 000 128 000
which I can verify with the Picoscope, then the 08M2 restarts.

Why is serout corrupt after using serin?
 

AllyCat

Senior Member
Hi,

Pin C.5 is the Serial Programming input, so the PICaxe is probably resetting in preparation for receiving a new download, when you send any character to the chip. You probably need to use a #DISCONNECT command at the start of the program and/or replace the SERIN with SERRXD (which automatically generates a DISCONNECT). In either case you will then need to use the "Hard Reset" procedure when you DO want to re-program the chip.

You will of course need to allow considerable time delays between sending characters to the PICaxe, since it's going to spend lots of time processing those SEROUTs and the PAUSE 4000, etc. And do you really need it to work at 38400 baud?

I'm just completing a similar project (i.e. Serial Input to I2C converter in an 08M2) but using HSERIN (with interrupts and a circular buffer) and HSEROUT (for debugging/testing) which both happen to use the same pins. It can give fully asynchronous operation, including concatenated (non-spaced) input characters, but has proved to be a considerable Can Of Worms, requiring very careful coding (and several bug workarounds) to achieve a maximum of 19200 baud.

Cheers, Alan.

PS: If you're sending the characters back to the PE6 terminal, then you should use N_38400 polarity or SERTXD.
 
Last edited:
I have an 8x2 OLED with a program for the 18M2 I modified to allow 38.4K baud because if it can go that fast then why not.
I was just trying T serial to see if it would help and it turns out N is better, I dont know why N is considered inverted.
I forgot about the disconnect command, that would explain the strange behaviour.

I've got I2C communication with the LC89091JA now I just have to figure out the commands.
 
Top