View previous topic :: View next topic |
Author |
Message |
AJEFenConsultancy
Joined: 09 Sep 2010 Posts: 11 Location: Ely, UK
|
No RS232 data from PIC16F1827 |
Posted: Sat Apr 16, 2011 5:12 am |
|
|
Hi,
Having resolved an issue with my micro not running, I have moved on to using RS232 comms. I have written the following test code:
Code: |
#include <16F1827.h>
#include <stdio.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, NOMCLR
#use delay(clock = 8000000)
#use rs232(baud=2400, xmit=PIN_B5, rcv=PIN_B2, PARITY=N, BITS=8, STOP=1, STREAM=PC)
void main(void)
{
while(1)
{
printf("Testing123");
output_toggle(PIN_B3);
}
}
|
I am not receiving any data at my PC. I have observed PIN_B5 with an oscilloscope, but there is no wave form at all. I can however see that PIN_B3 is toggling so I know the micro is running.
I have used the same set on other PICs and not had any problems.
Could someone guide me as to what the issue is please?
Thanks in advance.
Andrew _________________ Kind regards
Andrew Ellis |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Apr 16, 2011 7:33 am |
|
|
I believe if you declare the stream in your use RS232 statement you must use it in your printf statement. Or you can leave it out of both.
I don't have materials to check that out right now. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Apr 16, 2011 7:42 am |
|
|
Unfortunately, PCM misses to set the TXCKSEL bit in APFCON1 to select RB5 for TX output.
Code: | #bit TXCKSEL = 0x11e.0
...
TXCKSEL = 1; |
|
|
|
AJEFenConsultancy
Joined: 09 Sep 2010 Posts: 11 Location: Ely, UK
|
|
Posted: Sun Apr 17, 2011 2:28 pm |
|
|
Hi guys,
thank you for your replies.
I have modified my code so that it now reads:
Code: |
#include <16F1827.h>
#include <stdio.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, NOMCLR
#use delay(clock = 8000000)
#use rs232(baud=2400, xmit=PIN_B5, rcv=PIN_B2, PARITY=N, BITS=8, STOP=1, stream=PC)
#bit TXCKSEL = 0x11e.0
void main(void)
{
char c = 'H';
TXCKSEL = 1;
while(1)
{
fputc(&c, PC);
output_toggle(PIN_B3);
}
}
|
Unfortunately it is still not working. I have lifted pin B5 to ensure the is no load on it, but it is not toggling at all. Do you have any further suggestions please?
Thanks
Andrew _________________ Kind regards
Andrew Ellis |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Apr 17, 2011 5:15 pm |
|
|
or press F11 to get onscreen help ! |
|
|
AJEFenConsultancy
Joined: 09 Sep 2010 Posts: 11 Location: Ely, UK
|
|
Posted: Mon Apr 18, 2011 5:06 am |
|
|
Thanks for the suggestions.
I realised the mistake I made with fputc(); the code now reads:
Code: |
#include <16F1827.h>
#include <stdio.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, NOMCLR
#use delay(clock = 8000000)
#use rs232(baud=2400, xmit=PIN_B5, rcv=PIN_B2, PARITY=N, BITS=8, STOP=1, stream=PC)
#bit TXCKSEL = 0x11e.0
void main(void)
{
char c = 'H';
TXCKSEL = 1;
while(1)
{
fputc(c, PC);
output_toggle(PIN_B3);
}
}
|
Unfortunately it still is not outputting any data. Do you have any further ideas please?
Andrew _________________ Kind regards
Andrew Ellis |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Mon Apr 18, 2011 7:26 am |
|
|
What onchip peripherals does that PIC have on the same pin ? Normally you have to disable them when you use pins for a use other than the default use. Check the datasheet AND the CCS header for that PIC. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 18, 2011 12:07 pm |
|
|
I assume you're still using vs. 4.108 ? I looked at the .LST file, and I
can't make that version produce code for the hardware UART pins for the
16F1827. I tried various combinations of the main pins and the alternates
for Tx and Rx and I always saw it generate code for a software UART.
I didn't check to see if the software UART code will work or not.
How important is it for you to make this work ?
It is possible to write your own hardware UART routines. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=26631&start=7 |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Apr 19, 2011 1:51 am |
|
|
Quote: | I assume you're still using vs. 4.108 ? |
That's the bad thing when not telling the CCS version. Apparently, 16F1827 hardware UART is only working since V4.110. |
|
|
AJEFenConsultancy
Joined: 09 Sep 2010 Posts: 11 Location: Ely, UK
|
|
Posted: Tue Apr 19, 2011 4:14 am |
|
|
Hi PCM programmer.
Thank you for your reply.
I did submit a reply yesterday, but it didn't get posted for some reason? It's not the first time I've had a post disappear into oblivion
I'm still using version 4.108. I'll try using the UART example you suggested, but I think I'll need to upgrade the compiler.
Andrew _________________ Kind regards
Andrew Ellis |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Apr 19, 2011 5:39 am |
|
|
Quote: | but I think I'll need to upgrade the compiler |
I only checked in MPLAB simulator, that versions before V4.110 don't generate UART output, so apparently SFR addresses or initialization are incorrect.
As PCM programmer suggested, you are still able to access the hardware UART in your own code, using SFR definitions of the PIC16F1827 datasheet.. |
|
|
AJEFenConsultancy
Joined: 09 Sep 2010 Posts: 11 Location: Ely, UK
|
|
Posted: Thu Apr 21, 2011 5:08 am |
|
|
After a bit of haggling, I managed to get CCS to upgrade my compiler. So my problems are now resolved _________________ Kind regards
Andrew Ellis |
|
|
lscantillo
Joined: 02 Apr 2017 Posts: 13
|
|
Posted: Sun Apr 23, 2017 5:54 am |
|
|
AJEFenConsultancy wrote: | After a bit of haggling, I managed to get CCS to upgrade my compiler. So my problems are now resolved |
what was your final code? |
|
|
|