|
|
View previous topic :: View next topic |
Author |
Message |
Dutch2
Joined: 05 Oct 2007 Posts: 8
|
Using software serial port causes output pin to stop working |
Posted: Fri Feb 01, 2008 5:03 pm |
|
|
My project needs to communicate on a LIN bus. I hooked the (home grown) driver to the hardware UART pins on my 16F887 but I forgot that my driver inverts so I fixed it in software by switching to a software UART and using the INVERT function:
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=LIN, force_sw, invert)
#use fast_io(C)
set_tris_c(0b10000000);
Another pin on the same port (C1) controls a indicator light.
Code: | //fputc(0x00,LIN);
while (TRUE) {
output_toggle(Indicator);
delay_ms(100);
}
|
I wrote this simple test program after my main program failed when I started using the LIN bus.
Basically the loop flashes the indicator as long as the fputc is commented out. As soon as I uncomment it, the indicator stops flashing.
Any idea what I'm doing wrong here?
Thanks in advance,
D2. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 01, 2008 5:53 pm |
|
|
Quote: | I wrote this simple test program. |
Those are actually code fragments. Post a complete test program.
Here's an example:
http://www.ccsinfo.com/forum/viewtopic.php?t=32831&start=4
It has all statements that are needed to compile it: #include, #fuses,
#use, and a main(), and the minimum lines of code needed to test
the desired feature or problem. |
|
|
Dutch2
Joined: 05 Oct 2007 Posts: 8
|
|
Posted: Fri Feb 01, 2008 6:23 pm |
|
|
Code: | #include <16f887.h>
#fuses INTRC_IO,WDT,MCLR,NOPROTECT,BROWNOUT,BORV40,NOLVP
#device ADC=10
#use delay(internal=4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=LIN, force_sw, invert)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#define Indicator pin_c1
void init_system (void) {
set_tris_a(0b11111111); //Port a i/o
set_tris_b(0b11111111); //Port b i/o
set_tris_c(0b10000000); //Port c i/o
set_tris_d(0b10000000); //Port d i/o
set_tris_e(0b00001111); //Port e i/o
output_c(0b10000000);
output_d(0b10110000);
setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(0x300FF);
setup_wdt(WDT_144MS);
}
void main(void) {
init_system();
//fputc(0x00,LIN);
while (True) {
output_toggle(Indicator);
delay_ms(100);
restart_wdt();
}
}
|
PCM version 4.065 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 01, 2008 6:41 pm |
|
|
Try a more simple test program:
Code: | #include <16F887.h>
#fuses INTRC_IO,MCLR,NOPROTECT,BROWNOUT,BORV40,NOLVP
#use delay(internal=4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=LIN, force_sw, invert)
#define INDICATOR PIN_C1
//============================
void main(void)
{
fputc(0x00, LIN);
while(True)
{
output_toggle(Indicator);
delay_ms(100);
}
} |
|
|
|
Dutch2
Joined: 05 Oct 2007 Posts: 8
|
|
Posted: Fri Feb 01, 2008 6:58 pm |
|
|
Yep, that works. Any idea what is causing this?
Thanks,
D2. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 01, 2008 7:04 pm |
|
|
Add the lines of code back in, one or two at a time, until it fails.
See which line causes the failure. |
|
|
Dutch2
Joined: 05 Oct 2007 Posts: 8
|
|
Posted: Sat Feb 02, 2008 10:21 am |
|
|
Whenever I use fast_io for port C it stops working.
I checked another project where I used a software serial port on port B where I did not encounter this issue.
Code: | #include <16f876a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#device ADC=10
#use delay(clock=16000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, stream=PC)
#use rs232(baud=19200, xmit=PIN_B4, rcv=PIN_B5, stream=LIN, invert)
#use fast_io(b)
#use fast_io(c) |
Any ideas why I am seeing this issue now?
D2. |
|
|
Ttelmah Guest
|
|
Posted: Sat Feb 02, 2008 11:17 am |
|
|
Because on that project you were using the hardware serial on port C.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|