PDA

View Full Version : Serin EEPROM Programmer



dirtbiker5627
- 23rd February 2010, 04:46
I have spent two days trying to figure this out. I have a feeling it has to do with the SERIN command. Please help.
------------------------------------------------------------------------
define OSC 4
Define CHAR_PACING 500

CMCON0 = 7
ANSEL = %00000000

cont con %10100000
scl var GPIO.5
sda var GPIO.4
sout var GPIO.2
sein var GPIO.1
addr var byte
wr var byte
val var byte

Main:

serout sout, 6, ["To write to EEPROM press w", 13, "To read EEPROM press r", 13]
serin sein, 6, wr
if (wr = "w") then goto ewrite
if (wr = "r") then goto eread
goto main

ewrite:

serout sout, 6, ["Write", 13]
serout sout, 6, ["Enter address 0 - 15", 13]
serin sein, 6, addr
serout sout, 6, ["Enter value 0 - 255", 13]
serin sein, 6, val

i2cwrite sda, scl, cont, addr, [val]
pause 10

serout sout, 6, ["Write complete", 13]
goto main

eread:

serout sout, 6, ["Read", 13]
serout sout, 6, ["Enter address 0 - 15", 13]
serin sein, 6, addr

i2cread sda, scl, cont, addr, val
pause 10

serout sout, 6, [#val, 13]
serout sout, 6, ["Read complete", 13]
goto main
------------------------------------------------------------------------

Archangel
- 23rd February 2010, 04:58
Hello dirtbiker. . .
Welcome to the forum.
Please Give us a hint, which PIC are you using?
Just right off the top of my bald head . . .
TRISIO=%00000010

dirtbiker5627
- 23rd February 2010, 15:32
I am using the pic12f683

aratti
- 23rd February 2010, 18:34
i2cread sda, scl, cont, addr, val

i2cread sda, scl, cont, addr,[val]



Additionally variable addr must be a word not a byte!

Al.

dirtbiker5627
- 24th February 2010, 03:37
I changed TRISIO, put brackets around the [val] variable and changed addr to a word sized variable .When I start up the microcontroller it sends the first serial out command to the computer but when I send a serial command to the microcontroller from the pc the microcontroller goes into a loop and repeats the first serial command non stop until I disconnect the power.



define OSC 4
Define CHAR_PACING 1000

CMCON0 = 7
ANSEL = %00000000
TRISIO = %00000010

cont con %10100000
scl var GPIO.5
sda var GPIO.4
sout var GPIO.2
sein var GPIO.1
addr var word
wr var byte
val var byte

Main:

serout sout, 6, ["To write to EEPROM press w", 13, "To read EEPROM press r", 13]
serin sein, 6, wr
if (wr = "w") then goto ewrite
if (wr = "r") then goto eread
goto main

ewrite:

serout sout, 6, ["Write", 13]
serout sout, 6, ["Enter address 0 - 15", 13]
serin sein, 6, addr
serout sout, 6, ["Enter value 0 - 255", 13]
serin sein, 6, val

i2cwrite sda, scl, cont, addr, [val]
pause 10

serout sout, 6, ["Write complete", 13]
goto main

eread:

serout sout, 6, ["Read", 13]
serout sout, 6, ["Enter address 0 - 15", 13]
serin sein, 6, addr

i2cread sda, scl, cont, addr, [val]
pause 10

serout sout, 6, [#val, 13]
serout sout, 6, ["Read complete", 13]
goto main

Archangel
- 24th February 2010, 03:47
I changed TRISIO, put brackets around the [val] variable and changed addr to a word sized variable .When I start up the microcontroller it sends the first serial out command to the computer but when I send a serial command to the microcontroller from the pc the microcontroller goes into a loop and repeats the first serial command non stop until I disconnect the power.



define OSC 4
Define CHAR_PACING 1000

CMCON0 = 7
ANSEL = %00000000
TRISIO = %00000010

cont con %10100000
scl var GPIO.5
sda var GPIO.4
sout var GPIO.2
sein var GPIO.1
addr var word
wr var byte
val var byte

Main:

serout sout, 6, ["To write to EEPROM press w", 13, "To read EEPROM press r", 13]
serin sein, 6, wr
if (wr = "w") then goto ewrite
if (wr = "r") then goto eread
goto main

ewrite:

serout sout, 6, ["Write", 13]
serout sout, 6, ["Enter address 0 - 15", 13]
serin sein, 6, addr
serout sout, 6, ["Enter value 0 - 255", 13]
serin sein, 6, val

i2cwrite sda, scl, cont, addr, [val]
pause 10

serout sout, 6, ["Write complete", 13]
goto main

eread:

serout sout, 6, ["Read", 13]
serout sout, 6, ["Enter address 0 - 15", 13]
serin sein, 6, addr

i2cread sda, scl, cont, addr, [val]
pause 10

serout sout, 6, [#val, 13]
serout sout, 6, ["Read complete", 13]
goto main
Where does it go if wr<>r and <> w?
Main
Give yourself a third option to gather serial data, if wr has z in it and never receives the r or w or receives R or W
it will loop in main forever. You could serout sout,6,[" I received ",#wr] so you know what it got . . .

aratti
- 24th February 2010, 19:11
Since you made variable addr a word then you have to change your serin command to receive two bytes to be combined into one word. This means you have to Tx two bytes (SERIN is unable to receive word)




serin sein, 6, addr

serin sein, 6, addr.byte0,addr.byte1


Al.

dirtbiker5627
- 24th February 2010, 19:24
I have decided to narrow it down just to the SERIN command. I made a program to read the serial command from the pc and then transmit it back to the pc. When I send the serial data to the pic the transmit light flashes so I know the pc is sending the serial data but the pic is not retransmitting it back to the pc. I am using the debug terminal from the basic stamp program and Parallax USB2SER Development Tool.
http://www.parallax.com/Portals/0/Images/Prod/2/280/28024a-L.jpg



val var byte

TRISIO = %00000010

main:
serin GPIO.1, 6, [val]
pause 10
serout GPIO.2, 6, [val]
pause 10
goto main

aratti
- 24th February 2010, 20:59
SERIN doesn't need square bracket. Within bracket you will place the qualifier, not the variable.



serin GPIO.1, 6, [val]

serin GPIO.1, 6, val



Al.

dirtbiker5627
- 24th February 2010, 21:48
I took the Brackets off the SERIN command and it still does not work.

aratti
- 24th February 2010, 22:12
The USB2SER is not able to program BASIC Stamp® microcontroller modules. BASIC Stamp modules
require an inverted signal. If you need to program a BASIC Stamp use the FTDI USB to Serial Adapter


The above is from USB2SER data sheet, and it seems you should use TRUE STATE. Tray to change to:

serin GPIO.1, 2, val

and

serout GPIO.2, 2, [val]

(see PBP manual pag 130)

Al.

dirtbiker5627
- 24th February 2010, 23:48
I hooked up the serial input from my pc and tested it on my oscilloscope. What I got was not a serial data string but something similar to a triangular waveform. I looked up the datasheet for the ftdi chip. I fixed it by adding a pulldown resistor to the output of the ftdi chip. Thanks for everybodys help.



val var byte

TRISIO = %00000010
CMCON0 = 7
ANSEL = %00000000
main:
serin GPIO.1, 6, val
if (val = "a") then ser
goto main

ser:
Serout GPIO.2, 6, ["Got a"]
pause 10
goto main