18F1230 UART Issue

Forum for problems or queries regarding Flowcode Comms Components. Eg LIN, I2C, SPI, RS232, CAN, IrDA etc

Moderators: Benj, Mods

Post Reply
Cris
Posts: 16
Joined: Sun Nov 02, 2008 7:25 pm
Contact:

18F1230 UART Issue

Post by Cris »

Hello,
I’m using the 18F1230 and having problems with the RS232 function. I have tried various chip compiler settings ex. Int/ext clock source at different frequencies and baud settings. No matter how I set it up it fails to work in the real world, the setup is TTL to TTL. I’m using Pickit 2 to monitor and communicate with the chip. I have made a simple program to operate an LCD, the program displays “no communication” when nothing is sent to it (255) and transmits 255 out to verify it is able to transmit. The display should show “three” or “two” if (3) or (2) is sent via the Pickit 2 in UART mode. The program always simulates perfectly in FlowCode but fails the real world test.
I can see the chip transmitting to and receiving info from the Pickit 2 on screen and with my oscilloscope but the LCD just shows “no communication”. I had compiler issues that I posted here before with this chip and was given an updated FCD file and my compiler problems were cured. Is there a bug with the 1230 that I’m unaware of in terms of the UART function. Any thoughts would be appreciated. I have attached my test program for consideration. Thanks.

Cris
Attachments
RS232 TEST.fcf
(7.5 KiB) Downloaded 412 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 18F1230 UART Issue

Post by Benj »

Hello Cris

If you are using a 4MHz crystal then maybe try changing the Oscillator configuration setting from HS to XT. I would also disable the "Enhanced CPU Enable Bit" in the configuration.

Other then this you should be ok.

Cris
Posts: 16
Joined: Sun Nov 02, 2008 7:25 pm
Contact:

Re: 18F1230 UART Issue

Post by Cris »

Hello Ben

Sorry for the delay in replying, after updating my profile I was temporarily locked out of my account.

Thanks for the help, I made the changes you suggested including switching out my 8MHz crystal for a 4MHz. I still have the same problem with seeing the communication happening between my Pickit2 and the 18F1230 TX and Rx with the oscilloscope at the TTL level but still it doesn’t respond. I tried with all kinds of different config/baud settings, also tried the same type settings using a 16F877 to try and communicate with the 1230 instead of the Pickit2 but still no luck. I’m working on a project that will use the 877 to communicate with the 1230 and have built the board for these chips (and others) so I would really like to get to the bottom of this. To ensure the problem is not with my programming or board construction I am using the simple little program I uploaded to your site and a breadboard to try and sort it out.

If you have any other ideas I would appreciate your input. Thanks for sticking with me Ben.

Cris

Cris
Posts: 16
Joined: Sun Nov 02, 2008 7:25 pm
Contact:

Re: 18F1230 UART Issue

Post by Cris »

Ben,

I did some more testing and I have a situation with the 1230 where anything in the program that does not require an external input works. I put three different messages in a program, two that would work without any external inputs just a short delay between them and one requiring an external input. The LCD displays the two messages correctly but fails to display the one requiring the external input.

I made another little program just using one external switch and two LED’s, the one not requiring the switch to operate works fine and the other LED depending on the switch fails to operate.

Is there a situation where this would occur? If not I may have a damaged chip in my hands.

Cris

:roll:

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 18F1230 UART Issue

Post by Benj »

Hello Chris

It seems unlikely that you have damaged the chip in your hands they are normally quite resilliant though I guess it is possible if you have accumulated a large amount of static before handling the devices.

With your input switch are you pulling the input to both rails. eg with a circuit like this.

5V
|
\
|---------uC pin
[]
|
GND

the [] shown above is a resistor (1 - 10K).

Leaving a pin floating will not work correctly. I spent many an hour banging my head against a wall in my early days figuring this one out :)

Maybe also send in your LED program and the associated C file just to confirm the code is being generated ok. Though im sure there is not much that can go wrong with this.

Cris
Posts: 16
Joined: Sun Nov 02, 2008 7:25 pm
Contact:

Re: 18F1230 UART Issue

Post by Cris »

Hello Ben

I did not tie anything to ground, I usually don’t and haven’t had problems before but I guess there’s always a first time. Do I need to tie all unused pins to ground or just the ones I’m using as inputs.
I have attached the requested files for you to have a look at.

Cris
Attachments
BUTTON TEST.c
(2.45 KiB) Downloaded 406 times
BUTTON TEST.fcf
(6 KiB) Downloaded 384 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 18F1230 UART Issue

Post by Benj »

Hello

Any pin your using as an input must be tied to 5V or Ground at all times as shown. Otherwise any reading you get on the pin when it is floating is very unreliable. Eg it may appear to work but going near the chip and coughing will probably make a floating I/O pin bounce up and down.

Eg

5V
|
\
|---------uC pin

Will not work and should be avoided.

The exception to this rule is when you are connecting an input pin to an output pin. Though you must make sure that the output pin is configured as an output before your readings on the input will be accurate. The I2C bus and some SPI busses have 10K pullup resistors to ensure that the bus is always reverted back to a known state.

Unused pins and output pins do not need to be grounded.

Your program, the configuration settings and the C code that is produced all looks fine to me.

Cris
Posts: 16
Joined: Sun Nov 02, 2008 7:25 pm
Contact:

Re: 18F1230 UART Issue

Post by Cris »

Hello Ben

I tied A0 to the negative rail with a 10K res no luck, tried A1 as an input as well with the same result. I also changed the config settings with both these inputs and it always worked like before, the LED in the program that dose not need the external input to operate worked fine but the one that needs the input fails.
I wasn’t holding my breath because it didn’t work with the LCD and RS232 setup that did not require external inputs, switches ect. to function. Do I need resistors on the TX and RC pins as well? I have another setup on a 877 utilizing RS232 with no resistors and it works fine, maybe I was just lucky.

Penny for your thoughts

Cris

Cris
Posts: 16
Joined: Sun Nov 02, 2008 7:25 pm
Contact:

Re: 18F1230 UART Issue

Post by Cris »

Ben

I did some more testing and found that A0, A1 and A4 (pins 1,2,3) will not except inputs but all other A and B port pins seem to be ok, the LED requiring an external input work. Also if I remove the button from the program and replace it with an RS232 input the program runs very erratically if at all, by erratically I mean the program seems to hang or the LED requiring an RS232 input will turn on even with no signal or connection to the TX/RX pins. I tried 10k resisters to the negative buss on the TX and RC pins and both the main program LED and the RS232 activated one stay off. Have you seen a situation like this before?

Cris
:shock:

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 18F1230 UART Issue

Post by Benj »

Hello Cris

I have had a look at your RS232 program and I think I can see whats going wrong. I have made some changes to the attached file.

I think that the problem was that you were only reacting to a received byte of 2 or 3. if you are typing these numbers in hyperterminal then the numbers sent are actually 50 and 51, the ascii representation of characters 2 and 3.

See here for more info.
http://www.asciitable.com/
Attachments
RS232 TEST.fcf
(6.5 KiB) Downloaded 403 times

Cris
Posts: 16
Joined: Sun Nov 02, 2008 7:25 pm
Contact:

Re: 18F1230 UART Issue

Post by Cris »

Hi Ben
I hear what your saying about the hyperterminal situation, it’s strange that it didn’t work when it was chip to chip communication either. I will play with it some more, but the file you uploaded must have been made with FlowcodeV4 because I can’t open it with my FCV3. Can you upload a V3 version to look at. Thanks Ben!

Cris

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 18F1230 UART Issue

Post by Benj »

Sorry Cris

Here is a v3 version of the file.
Attachments
RS232 TEST.fcf
(6.5 KiB) Downloaded 409 times

Post Reply