PDA

View Full Version : PIC18F2450 Rs-232



PlantBob
- 3rd February 2011, 13:58
I have a Olimex PIC-28 board. I have a PIC18F2450 and a ST232 installed.

I have pin 17 on the PIC18F connected to pin 12 on the ST232
I have pin 18 on the PIC18F connected to pin 10 on the ST232

I am using this command in PBP:
SEROUT PORTC.6,T9600,["This is a test"]

I have a scope attached and the PIC pins 17 and 18 are always high, they never change.

Is my wiring wrong? or do I have to set some configuration bits to make this work?

Thanks,
Bob

PlantBob
- 3rd February 2011, 13:59
BTW,
the SEROUT PORTC.6,T9600,["This is a test"] command is in a loop that updates every 2 seconds.

PlantBob
- 3rd February 2011, 14:02
More Information:

TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
TRISB = %00000000 ' Set PortB to outputs
TRISA = %01111111
SPBRG = 25 ' Set baud rate to 2400
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode
INTCON2.7 = 0

SKOLS1
- 3rd February 2011, 14:11
If you want to control ports.Frist of all change them to "0",with this command PORTB=$00

PlantBob
- 3rd February 2011, 15:08
TRISB = %00000000 is the same thing and that is already in my code.
I don't think Portb has anything to do with my USART operations.

mackrackit
- 3rd February 2011, 15:29
TRISB = XXX
PORTB = XXX
are not the same thing. One sets direction and the other is on/off.

What happens if you pull the 232 chip?

PlantBob
- 3rd February 2011, 15:36
Doing further research, it looks like I have to use HSEROUT withe the USART pins on the PIC18F2450. I have tested with HSEROUT and I still don't get any serial out.

Can I use other Pins and use SEROUT? if so what do I need to specify in my code? I have a 20mhz clock and need 9600,n,8,1

I disconnected the 232 chip and the result is the same.

SKOLS1
- 3rd February 2011, 15:44
Why do you put 9600bauds put 2400
please post the code!!

mackrackit
- 3rd February 2011, 15:46
I see what you did now.
Remove the hardware serial stuff.
SPBRG = 25 ' Set baud rate to 2400 RCSTA = %10010000 ' Enable serial port and continuous receive TXSTA = %00100000

Then you can use SEROUT on those pins. You may want to look at SEROUT2, has more options.

HenrikOlsson
- 3rd February 2011, 15:53
Hi,
You shouldn't have to use the USART but I see no apparent reason not to when it is on the same pins as you're trying to use with SEROUT.

If you're using SEROUT you can use any pin you like as long as it can be made an output but you must make sure that all other peripherals multiplexed to that particular pin is turned off. Start by doing a blink-a-led on the particular pin you want to use, when you have that working you should be able to get data out with the SEROUT or SEROUT2 commands.

By the way, setting RCSTA, TXSTA etc does not effect SEROUT/SERIN commands, only HSEROUT etc. With HSEROUT you have to use a levelconverter as it can't send the data inverted - as far as I know.

If you're going to use the USART you can only use the pins to which the USART is connected (PortC.5 and 6 in this case but some chips can switch them around to alternative pins). But again you need to make sure that any other peripheral that may be on the same pin isn't "taking over" so to speak.

/Henrik.

PlantBob
- 3rd February 2011, 16:09
Ok, here is what I have


DEFINE OSC 20
TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
TRISB = %00010000 ' Set TX (PortB.5) to in, rest outputs
TRISA = %01111111
SPBRG = 25 ' Set baud rate to 2400
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode
INTCON2.7 = 0

pinin VAR PORTB.4 ' Define pinin as PORTB.4
pinout VAR PORTB.5 ' Define pinout as PORTB.5

how do I setup the SEROUT command to send "This Is a Test" ?
how fo I setup the SERIN command to receive "Test Received" ?

ScaleRobotics
- 3rd February 2011, 16:46
What configs are you using? If it is the default ones in pbp/18f2450.inc then they are set to:



__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H,_PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_BB1K_4L & _XINST_OFF_4L


That should get you 48 mhz instead of 20 mhz.

And for the hardware, do you have the 3.3 volt jumper on, or off?

Can you get the chip to blink an LED or something to make sure its running?

If you decide to go with hardware uart here are some defines for 48 mhz.

'DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
'DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
'DEFINE HSER_SPBRG 77 ' 9600 Baud @ 48MHz, 0.16%
'DEFINE HSER_CLROERR 1 ' Clear overflow automatically

PlantBob
- 3rd February 2011, 19:01
I have an external 20mhz oscillator. Can you tell me what I need to do to use SEOUT2 and SERIN2 on pins PORTB.5 and PORTB.4?

ScaleRobotics
- 3rd February 2011, 20:17
I have an external 20mhz oscillator. Can you tell me what I need to do to use SEOUT2 and SERIN2 on pins PORTB.5 and PORTB.4?

Hi Bob,

Are you able to blink an led with the chip? It may sound stupid, but that eliminates a lot of other issues.

With the 20 mhz external OSC and the default configs, your chip will run at 48 mhz. So if you are using the default configs, you will have to define your OSC. You might also try Darrel's All Digital. It takes care of some of the analog settings that can throw us for a loop. It is located here: http://www.picbasic.co.uk/forum/content.php?r=154-All-Digital
Im away from my PBP right now, but you should be able to use the PBP serout example from the manual.

Let us know if you get stuck.

Bruce
- 3rd February 2011, 20:41
You definitely do not want to enable the hardware USART if you want to use any bit-banged serial routines like SEROUT/SERIN or SEROUT2/SERIN2 on the hardware RX/TX pins.

Enabling the hardware USART prevents you from using the TX/RX pins as digital, so bit-banged serial commands can't control these pins.

And double-check your connections to the ST232. I suspect you have TX and RX backwards.

ScaleRobotics
- 3rd February 2011, 21:02
And double-check your connections to the ST232. I suspect you have TX and RX backwards.

he is using this board http://www.olimex.com/dev/pic-p28.html so wiring should be correct. (for the hardware serial port that is)

Bruce
- 4th February 2011, 00:14
Pin 17, TX on the PIC, should connect to pin 10 on the 232.
Pin 18, RX on the PIC, should connect to pin 12 on the 232.

Not the other way around like he states in his 1st post.