PDA

View Full Version : Help with pic16f690 -max232cpe



krise86
- 17th April 2010, 12:55
So i started to try out some serial com and after alot of struggling i have gotten it almoste to work.

i have pickit2 with pic16f690 and a demoboard with max232.

max232:

pin 1 & 3 - 1uf
pin 4 & 5 - 1uf

pin 2 - 1uf to vdd
pin 15 - 1uf to gnd
and gnd to vdd 1uf

so i have been able to recive text on my computer from the pic but it's somehow malformed.

i try to send "Hello World", 13, 10
and i get
Hello0World<(8A)>

when i stop the pic i recive the space and cr and lf

when i make the pic hserout the hserin i returns random alphas or signs.

my current code is as follows:

Code:

DEFINE OSC 4

'intcon=0 ' Interrupts disabled
cm1con0=0 ' Comparator 1 disabled
cm2con0=0 ' Comparator 2 disabled
'cm2con1=0 ' Comparator 2 disabled

ANSEL=0 ' Pins to be Digital
ANSELH=0 ' Pins to be Digital

Include "modedefs.bas"

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h 'sets bergh = 1 or 20h sets = 0
DEFINE HSER_BAUDCON 0h ' 0h
DEFINE HSER_BAUD 9600 '16468
DEFINE HSER_SPBRG 25
'DEFINE HSER_CLROERR 1


main:
hserout ["Hello World", 13, 10]
pause 1000
goto main

and i cant figure out why!

im using picbasic with MC studio and MPASM

Please HELP

aratti
- 17th April 2010, 13:05
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 4MHz, 0,16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically




Tray to replace your USART setting with the one given above.

Al.

krise86
- 17th April 2010, 14:31
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 4MHz, 0,16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically




Tray to replace your USART setting with the one given above.

Al.

Thx for replying, but i have tried that to. and still no go. when i change the usart settings to use 2400 bauds it wont work at all, then i just get alphas and numbers.

can there be something wrong with my connections. iv tried with 2 max232 and same result. have i connected something wrong would this result in such an error.

and one thing more, when i send a alpha, let's say "t" if i repeat that like 10 timer with 50ms pause i revice the correct letter back maybe once <- if i look a hserin and hserout

aratti
- 17th April 2010, 15:54
What kind of terminal are you using?

Can you post your wiring ?

Al.

krise86
- 18th April 2010, 21:12
What kind of terminal are you using?

Can you post your wiring ?

Al.

Well it looks like i found the probleme, i looked over the max232 data sheet and i frogot to connect vcc and gnd:o

Now i recive the expected output but it wont read the input.



DEFINE OSC 4

'intcon=0 ' Interrupts disabled
cm1con0=0 ' Comparator 1 disabled
cm2con0=0 ' Comparator 2 disabled
'cm2con1=0 ' Comparator 2 disabled

ANSEL=0 ' Pins to be Digital
ANSELH=0 ' Pins to be Digital

Include "modedefs.bas"

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h 'sets bergh = 1 or 20h sets = 0
'define HSER_BAUDCON 0h ' 0h
'DEFINE HSER_BAUD 9600 '16468
DEFINE HSER_SPBRG 25
DEFINE HSER_CLROERR 1

rxVal Var Byte
HSEROUT ["Waitin signal"]
main:
hserin [rxVal]
hserout [rxVal]
'HSEROUT ["Test should work"]
pause 20
goto main


Any ideas?

And Thx for the help so far, sorry for not checking the schematics better
and im using 232analyzer terminal software

aratti
- 18th April 2010, 21:25
Can you post the schematic?

Al.

krise86
- 18th April 2010, 21:56
Can you post the schematic?

Al.

http://3.bp.blogspot.com/_TwsOWSSueps/S8tx02A2uGI/AAAAAAAAABY/LUbna-oQJz0/s1600/pic16f690db9.jpg

aratti
- 18th April 2010, 22:56
Something doesn't work with your wiring:

Max232 pin 10 should be connected to pic 16F690 pin 10 (RB7 Tx)

Max232 pin 9 should be connected to pic 16F690 pin 12 (RB5 Rx)

Connect a decoupling capacitor 10nF from Vdd to Vss on pic power pins.

Al.

krise86
- 18th April 2010, 23:18
Well it is connected that way pin 10 -> rb7 and pin9 -> rb5

The 16f690 was not in the schematics program but that how i connected it.

but im reading -10v on rs232 pin 3 and 5 is that right?

I dont have a 0,01uf can i use 0,1uf?
wait i think it's on the demo board

aratti
- 18th April 2010, 23:21
but im reading -10v on rs232 pin 3 and 5 is that right?


Yes! Max232 is a voltage level translator.


I dont have a 0,01uf can i use 0,1uf?

Yes!

Al.

krise86
- 18th April 2010, 23:31
Yes! Max232 is a voltage level translator.



Yes!

Al.

That did nothing, is there a way to check if the signal is coming out from pin 9 on max232?

aratti
- 18th April 2010, 23:48
That did nothing, is there a way to check if the signal is coming out from pin 9 on max232?

Yes place a led with 1K in series from pin 9 to gnd.

But, I am more interested on how many IO pins you are using. Now If you have inputs pins floating (not connected) this can produce wierd result.

I noted in your code, that you are not setting the tris registers, please do it. Set all non used pins as output and place them to a logic zero.

Example (I assume you are using only the serial pins) :

TrisA = %00000000
PortA = 0

TrisB = %00100000 ' if the only input is pin 10 Rx
PortB = 0

TrisC = %00000000 ' if none of the portC pins are used
PortC = 0

The above code has to be written on top of your code. It will set all non used port as outputs @ logic zero, avoiding to leave inputs floating.

If your arrangement is different modify the tris command to suite your need.

Al.

krise86
- 19th April 2010, 00:24
Yes place a led with 1K in series from pin 9 to gnd.

But, I am more interested on how many IO pins you are using. Now If you have inputs pins floating (not connected) this can produce wierd result.

I noted in your code, that you are not setting the tris registers, please do it. Set all non used pins as output and place them to a logic zero.

Example (I assume you are using only the serial pins) :

TrisA = %00000000
PortA = 0

TrisB = %00100000 ' if the only input is pin 10 Rx
PortB = 0

TrisC = %00000000 ' if none of the portC pins are used
PortC = 0

The above code has to be written on top of your code. It will set all non used port as outputs @ logic zero, avoiding to leave inputs floating.

If your arrangement is different modify the tris command to suite your need.

Al.
I did that now but still nothing usful, it seems that the data is coming out from the max but it wont register at all i do get something when i send like 200 times with 10ms

ScaleRobotics
- 19th April 2010, 00:56
Is the ground (pin #5) of the serial connector really connected to +5 volts like the schematic?

krise86
- 19th April 2010, 01:02
Is the ground (pin #5) of the serial connector really connected to +5 volts like the schematic?

No just i did not lay to much work in the schematics. but no it's connected to ground

krise86
- 19th April 2010, 01:06
here is the updated right one.

And i found a probleme wich seems od. when using any freq other than 4mhz the buad rating is all wrong.
check out this forum discussion about it

http://www.mikroe.com/forum/viewtopic.php?f=13&t=11114

krise86
- 19th April 2010, 01:23
I found another forum thred about turning the MCLRE_OFF

how do i do that?

ScaleRobotics
- 19th April 2010, 01:32
I found another forum thred about turning the MCLRE_OFF

how do i do that?

Check the configuration word register. Page 201 of the data sheet.

krise86
- 19th April 2010, 01:44
Check the configuration word register. Page 201 of the data sheet.

that okey, but how do i do it in picbasic?

ScaleRobotics
- 19th April 2010, 02:14
You can put them in your program, or you can edit them in PBP files. Either way, you will have to go to your PBP files, and find the one specific to your chip. Look for the 16f690.inc file, and either edit, or comment out the line



; __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
__config _HS_OSC & _WDT_ON & _MCLRE_OFF & _CP_OFF


It is easiest to just to comment it out, then copy and paste it back into the same file with your changes. That way you will be able to go back to the default. Many people prefer to comment it out in this file, then put it into their PBP code. To to this, you would add a line at the top of your program, like this:



@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF


See http://www.picbasic.co.uk/forum/showthread.php?t=543 for a more in depth look

krise86
- 19th April 2010, 02:34
Okey so still working on this. i have registred that the rb5 is reciving something, what i dont know.

So i looked at the max232 sheet and it says there should be a +10v on port 2 and -10v on port 6 but im reading -2.3 and +6.5 could that be the reson?

malc-c
- 19th April 2010, 07:24
Can you provide details of the computer you are hooking this up to. Some laptops don't have enough "umph" to provide the voltages required when using PIC programmers, so it might be the same with the project your are working on.

krise86
- 19th April 2010, 12:49
Can you provide details of the computer you are hooking this up to. Some laptops don't have enough "umph" to provide the voltages required when using PIC programmers, so it might be the same with the project your are working on.

it's an self built desktop. with asus p6d motherboard and it should do the trick. but i have an pci serial with power options for setting up to 4 pins to 5 or 12 v.

but i see that the voltage from the pickit is 4.8 maybe i should connect an ext pw sup?

it's irritating because this should be such a small case and iv been stuck at this since like friday.

And to all Thx for all the help so far!

krise86
- 19th April 2010, 20:35
Now i have tried external pw and still no go. the pics sends fine, but wont recive. I have no other ideas left.

other than if the voltage on pin 2 and 6 on the max is +6 and -2 but should be +10 nad -10. what am i doing wrong?

ScaleRobotics
- 19th April 2010, 21:08
Can you post your entire code with the trisb and all ... plus whatever code you are using to determine it is not receiving.

Thanks,

Walter

krise86
- 20th April 2010, 09:41
DEFINE OSC 4

ANSEL = %00000000 ' Pins to be Digital
ANSELH = %00000000 ' Pins to be Digital
TrisA = %00000000
PortA = 0
TrisB = %00100000 ' if the only input is pin 10 Rx
PortB = 0
TrisC = %00000000 ' if none of the portC pins are used
PortC = 1

CM1CON0 =0
CM2CON0 =0
CM2CON1 =0

adcon1=0

Include "modedefs.bas"

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h 'sets bergh = 1 or 20h sets = 0
'define HSER_BAUDCON 1h ' 0h
DEFINE HSER_BAUD 2400 '16468
DEFINE HSER_SPBRG 103
DEFINE HSER_CLROERR 1
rxVal Var word

start:
Hserout ["Hello World", 13, 10] ' Send text followed by carriage return and linef
main:
Hserin 10000,start,[rxVal] ' Get a char from serial port
Hserout ["Got value:", rxVal] ' Send char out serial port
pause 30
goto main

That's the code.

mackrackit
- 20th April 2010, 13:15
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 2400 Baud @ 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

The above should be for 4MHz.
Can you also post your configs and what are you using for an OSC?

krise86
- 20th April 2010, 15:56
I have already tried that, so it's still a no go.

But no one has commented on the voltage levels of the max. it should say 10 but i dont get it higher than 7. when i rebuild the whole shematics on the breadboard the voltage got i little better but still no higher than 7

aratti
- 20th April 2010, 19:31
But no one has commented on the voltage levels of the max. it should say 10 but i dont get it higher than 7. when i rebuild the whole shematics on the breadboard the voltage got i little better but still no higher than 7

Check the capacitors used. See snap attached for value.

Al.

Dave
- 20th April 2010, 20:03
krise86, Depending on the capacitator values used with a MAX-232 the charge pump voltages should be around +-6 volts to +- 9 volts. The TRUE RS-232 spec calls out for mark,space voltages of +- 3 volts minimum... Some laptop computers now days do not meet the TRUE RS-232 spec limits as some only put 0 to +5 volts... That is why some laptop computers don't have a solid serial communications...

Dave Purola,
N8NTA

krise86
- 20th April 2010, 23:32
Yeah i am using 1uf caps, so it's not that. and i am reciving at this moment v- = -1.86 and v+ = 6.96.

I found out that i can use the pickit 2 as logic analyzer. and i see the bytes roll inn when the pic send out to pc but not ther other way around.

Im stumped... this sould work!
I have followd all the guidelines and shematics and caps. i have also oredered some new max and pic's. also alot of caps and resistors. I really want this to work.

Thx for all the help so far. i will get this to work! i hope

krise86
- 21st April 2010, 00:54
Okey so finally i got this working, but the story about how i did it is kinda BAD.

So after a while i was beginning to wonder why it was reading wrong voltages. and i knew the connections where right, until i look really close to the serial cabel, i used a rs232 to rj45 and a cat5 cabel, but i somehow got the colors mixed up. So ground was not connected.:o heh.... well u think stupid you, and yes stupid me. not going to that mistake again. So then i started to check the connection on my breadboard and pow it splits in the middel where i had put my pic. so basicly i had half of the earth connections not connected. And i connected it this way after it was connected the right way. but then i did not have the pin 5 from rs232.

Maybe it's a lesson to learn from all of this. ALWAYS check ur cabel and make sure pin5 is connected.

BTW how many times have i answerd What colour is a ripe tomato?
lost count:)

Sorry to have wasted everybodies time but i really appricihate it.

And i did learn alot from searching and reading around the net.

Thx for all the help once again and sorry that im such an idiot

mackrackit
- 21st April 2010, 01:13
:)
Glad you got it working.
Do not be sorry for making a mistake, it happens to all of us.
I spent a just spent a couple days in something and the problem was not turning the ADC off!!! How many times have I told others to check that? More times than a tomato is ripe!!!

krise86
- 21st April 2010, 01:27
yeah:D but still.
One more question tough. why cant i run a for loop?

for count = 1 to 40
pulsout PORTC.1,200
pause 20
next count

mackrackit
- 21st April 2010, 02:01
COUNT is a reserved word, a command actually.
Change it to CNT ot something and it should work.


for CNT = 1 to 40
pulsout PORTC.1,200
pause 20
next CNT

krise86
- 21st April 2010, 02:26
i ended up with a while loop, but il try the for loop.

Thx for the help. Il be coming back, waiting for a gps module it should be here in a couple of days:D


i = 1
while i<40
pulsout PORTC.1,pos
i=i+1
pause 20
wend

the for loop gave me and syntax error

mackrackit
- 21st April 2010, 02:43
the for loop gave me and syntax error

Did you try CNT? Did you declare CNT as a variable?