Problem Picaxe 40x1 GSP VDIP1

ace_gigi

New Member
Partially Solved Picaxe 40x1 GSP VDIP1

Hi,
I have 2 problem for serial com (picaxe40x1):

1) gps[EM406A] txd connected directly to 40x1
if I use serin command on input pin0[leg 19] it works:
serin[10000,nodata],GPSRX,T4800,("$GPRMC,"),b1,b2,b3,b4,b5,b6,b0,b7,b8,b9,b0,b10,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b11,b0,b12,b13,b0,b14,b15,b16,b0,b17,b18,b0,b19,b20,b21,b22,b23,b24

if I use Hserin on pin7 [leg 26] read every byte 0. Also when the read routine is finish the picaxe reset
the code
#picaxe 40x1
SetFreq m8
#terminal 9600

HSERSETUP B9600_8, %00

main:
sertxd("start",cr,lf)
HSERIN [10000,leggi],b0,10,("$")
sertxd("fine",cr,lf)
goto main

Leggi:
FOR b0 = 0 to 5
read b0, b1
bintoascii b1,b2,b3,b4
SERTXD ("dato:",#B1,"_bintoascii:",b2,b3,b4)
NEXT b0
SERTXD (cr,lf)
pause 10000
return

2)VDIP1 (Vincuulum) connected directly to 40x1
'porta pin2 RX da Vdip1--I tried also pin7
'portb pin6 TX verso Vdip1
'porta pin3 RTS (verso) Vdip1 (not essential, can tie to 0V)
'portb pin5 CTS (verso) Vdip1 (not used)

doesn't read correctly because read ascii(141) ascii(182) ascii(140) instead "E"

if I use picaxe 18x input pin 6 (RXD) and output pin7(Txd) Vdip1 work correctly

the code
sertxd ("<Sent> E",CR,LF)
serout 6,T4800,("E",CR)
sertxd ("serin",CR,LF)
serin [30000,nodata1],7,T4800,b0,b1,b2'RxVdip1
sertxd ("serin fine_",b0,"_",b1,"_",b2,"_",CR,LF)
pause 100
if b0 <> "E" then init '"E"
 
Last edited:

inglewoodpete

Senior Member
I think you misunderstand the use of hserin and the scratchpad memory.

Code:
HSERSETUP B9600_8, %00
   -and-
HSERIN [10000,leggi],b0,10,("$")
   -and-
Leggi:
FOR b0 = 0 to 5
read b0, b1
HSERSETUP B9600_8, %00 tells the PICAXE to use backgroud receive to the scratchpad RAM.

read b0, b1 tells the PICAXE to read data from the EEPROM.

You need to understand the scratchpad operators 'Get', 'ptr', '@ptr' and '@ptrinc'
 

Dippy

Moderator
Probably a voltage problem. I havn't looked at you code.

PIC chips have 2 types of input module. TTL and ST. They have different input 'sensitivites'.

That GPS output is less than 3V - in fact, in a Data Sheet it says 0 - 2.85V TTL.

You say you used Serin on Input 0 . That would be physical pin 19?
Input 0 (physical pin 19?) = PIC PortD.0 is a 'TTL' input.
It will see an Input = High/1 at 2V and above when PICAXE powered at 5V.
i.e. 2V is like a threshold and any voltage over 2V is seen as High (or digital 1)
So, that's fine with your GPS where a High/1 is at 2.85V.

However, the HSerin pin (physical pin 26) uses the PIC EUSART and is a Schmitt Trigger (ST) input.
This will require 0.8 x Vsupply to 'see' an Input High/1.
So, when PICAXE at 5V it will need a pulse height = 0.8 x 5 = 4V to get a high (man).
As your GPS outputs a high as less than 3V it will never see a high.
So, NOT OK.

I really wish this bit of info was in PICAXE Data Sheets as it crops up a lot.

I'm afraid it currently requires the user to wrestle with Microchips PIC Data Sheets.
 

Dippy

Moderator
Have a look at this. Even if this isn't the problem it's still handy info which isn't in the PICAXE Data Sheets currently.

If this is the problem and you wish to connect to Hserin, then you have 2 options.
Level shift UP the output from the GPS.
Or reduce the supply voltage to PICAXE - I'll leave to calculate the Vdd you require.

EDIT: Looks like it could be code and voltage ;)
No doubt someone will say: "Its code and voltage" after reading our posts.
 

Attachments

Last edited:

ace_gigi

New Member
inglewoodpete: ok, but in the first code I use get and the result is the same
Dippy: I suppose the same thing, also I tried, for a test, with a 74ls08 between gps and pic but nothing change..

Input 0 (physical pin 19?).. yes

TTL and ST.
I read about that, but I have a problem because the only ST I have in 40x1 are on portc, and i cannot use portc with serin command :-((
in the evenign I whant to try to use a 4n25 (optocoupler) between gps and 40x1, to generate the correct signal.

Thanks a lot
 

Dippy

Moderator
No, no. You don't want to use an ST input unless you can level shift or run PIC at lower voltage (i.e. if it practical and doesn't upset other things. Without knowing what else is connected to your PICAXE I can't say).

If you start using optocouplers beware of data inversion.

How good is your electronics? You know about using transistors?

Anyway, good luck. I'm sure you'll get it sorted as you now know the paths.
 

ace_gigi

New Member
My electronics is pretty good, I prefer use optocouplers instead a transistor because I want to opto-isolate the signal, and it's easy change resistor to change the value.

On picaxe 18x I use ST and still comm with VDIP1
 

Dippy

Moderator
18X Input 0 & 1 are TTL and 6&7 are ST.

Maybe the 3.6V from VDIP1 is just enough for ST. I'm sure there is some tolerance. Maybe you got lucky. Anyway, it works and obviously you have been reading Data Sheets.

But the <3V from that GPS is way too low for ST with PIC @5V.

You'll have it sussed soon.
Good luck.
 

Technical

Technical Support
Staff member
As already pointed out, you can't mix automated background hserin (into scratchpad, configured by hsersetup) and manual hserin processing (via the hserin command) together. Use one or the other.
 

hippy

Ex-Staff (retired)
In your code (abridged) ...

main:
sertxd("start",cr,lf)
HSERIN [10000,leggi],b0,10,("$")
sertxd("fine",cr,lf)
goto main

Leggi:
FOR b0 = 0 to 5
read b0, b1
:
return

If the HSERIN times out it executes a 'GOTO Leggi', without a previous GOSUB the RETURN is unpredictable. This is probably the cause of the reset. That RETURN should likely be a "GOTO main".

Your READ does not retrieve data from the scratchpad.

Also after executing the FOR-NEXT, b0 is left with value 6 which is then ( would be ) used when HSERIN next executes, writing to a different area of scratchpad than before.
 

ace_gigi

New Member
Technical: i can't understand
Hippy: you are right for read, I make a mistake, but before there is a get instruction..
So, if I understand:
main:
b0 = 0 '<-- added
sertxd("start",cr,lf)
HSERIN [10000,leggi],b0,10,("$")
sertxd("fine",cr,lf)
goto main

Leggi:
FOR b0 = 0 to 5
GET b0, b1 ' before(read)
:
goto main ' before(return)

or

main:
b0 = 0 '<-- added
sertxd("start",cr,lf)
HSERIN [10000,leggi],b0,10,("$")

get b0,b1
if b1="$" then
FOR b0 = 0 to 5
GET b0, b1 ' before(read)
next b0
end if
sertxd("fine",cr,lf)
goto main
 
Last edited:

ace_gigi

New Member
Goodmornig,
I partially solved my problem.

GPS-em406a to hserin
I use a 74ls08:
input A connected to +5V
input B connected to txd gps
output Y connected to 40x1

it's work fine

the code
ackGps:
'leggi da GPS
b0=0
SEROUT 7,T4800,("$PSRF103,01,01,00,01*24",CR,LF)
HSERIN [1000,readout],0,126,("C")
return
'I take this sub in this forum:
ReadOut:
gosub save_data
FOR b20 = 0 to 50
GET b20, b1 'get byte from scratchpad
if b1 = "," then
b1 = ";"
end if
if b1 = "." then
b1 = ","
end if
SERTXD (B1)
SEROUT 4,t4800,("wrf ",$00,$00,$00,$01,CR,b1,CR)
SERIN 0,t4800,RxVdip1 'wait for ACK
IF RxVdip1 <> 132 THEN ReadOut 'if no ACK start again
NEXT b20
SEROUT 4,t4800,("wrf ",$00,$00,$00,$03,CR,";",cr,lf,CR)
GOSUB Close_file
SERTXD ("",cr,lf)
return

Now i want to optimize this routine, because take to much time, in fact every ciclo do a serout.
It's possible to send all or partial contents of hserin on serout?
Any suggestion?


VDIP1
I tried the same code with the same circuit on 18x and 40x1, but i receive different serin char.
the code:
sertxd("StartInit",cr,lf)
pause 5000
'sertxd("**Start****",RET,LFEED)
sertxd("StartInitVDIP1",cr,lf)
; Send Echos until the unit USBKEY responds correctly
sertxd ("<Sent> E",CR,LF)
serout 4,T4800,("E",CR)
serin 0,T4800,RxVdip1 '<---FIRST
pause 100

sertxd(#RxVdip1,cr,lf)
if RxVdip1 <> 133 then init'"E" then init
; check to see if a drive is actually inserted
; response will start D for yes and N for no
serout 4,T4800,(CR)
serin 0,T4800,RxVdip1
sertxd(#RxVdip1,cr,lf)
pause 100
if RxVdip1 <> 132 then save_data '"D" then save_data '<---SECOND
; create a log file called 'log' (for some reason 'log.txt' didn't work)
serout 4,T4800,("opw log.csv",CR)
serin 0,T4800,RxVdip1
pause 100

serout 4,T4800,("wrf ",$00,$00,$00,$2B,CR,"Km;mt;ImpRpm;ImpSpd;Rpm;Spd;Rpm/Spd;Gear;",CR,LF,CR)
serout 4,T4800,("clf log.csv",CR)
serin 0,T4800,RxVdip1
pause 100

in both case it save correctly data on USB key, but
FIRST SERIN
18x 40x1
"E"[ascii(37)]<----->[ascii(133)]

SECOND SERIN
18x 40x1
"D"[ascii(36)]<----->[ascii(132)]

why? There is a bug on 40x1? or in my mind?


Thanks a lot
 
Top