 |
 |
View previous topic :: View next topic |
Author |
Message |
ralph79
Joined: 29 Aug 2007 Posts: 90
|
PICF18F26Q10 with double hardware uart |
Posted: Wed Sep 24, 2025 11:12 am |
|
|
Hi all,
Probably is a very stupid question, but it was been driving me nuts...
I have a PIC18F26Q10 with UART1 @ 9600 and UART2 @ 19200.
And the UART2 is not working, or in other words is works from only from times to times
the code is:
Code: | #include <18F26Q10.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOEXTOSC //External Oscillator not enabled
#FUSES RSTOSC_HFINTRC_64MHZ //On Power-up clock running from HFINTRC at 64MHz
//#FUSES NOCKS //Clock Switching Enabled
#FUSES NOFCMEN //Fail-safe clock monitor enabled
#FUSES NOMCLR //Master Clear pin enabled
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV19 //Brownout reset at 1.9V
#FUSES ZCDDIS //Zero-cross detect circuit is disabled at POR
#FUSES NOPPS1WAY //Allows only one reconfiguration of peripheral pins
#FUSES NOSTVREN //Stack full/underflow will cause reset
#FUSES WDTSW //Watch Dog Timer Postscale settable in software
#FUSES WDTWIN_SW //Watchdog Window is settable in software
#FUSES WDTCLK_SW //WDT clock source settable in software
#FUSES NOWRT //Program memory not write protected
#FUSES NOSCANE //Scanner module is available for use
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOEBTR //Memory not protected from table reads
#pin_select U1TX = PIN_C6
#pin_select U1RX = PIN_C7
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=PORT1, errors, restart_wdt) // UART1
#pin_select U2TX = PIN_B6
#pin_select U2RX = PIN_B7
#use rs232(baud= 19200, parity=N, xmit = PIN_B6, rcv = PIN_B7, bits=8, stream=portBT, errors, restart_wdt) /*UART2,*/
#use delay(internal=64MHz)//, restart_wdt)
#pin_select CCP1OUT=PIN_C2
#pin_select CCP2OUT=PIN_C1
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(E)
#priority INT_RDA2, INT_RDA
void init_micro(void)
{
setup_oscillator(OSC_HFINTRC_64MHZ);
set_tris_a(port_a_dir); // set data I/O directions
port_a_pullups(port_a_pull); // set internal pullups
set_tris_b(port_b_dir); // set data I/O directions
port_b_pullups(port_b_pull); // set internal pullups
set_tris_c(port_c_dir); // set data I/O directions
port_c_pullups(port_c_pull); // set internal pullups
set_tris_e(port_e_dir); // set data I/O directions
port_e_pullups(port_e_pull); // set internal pullups
setup_dac(OFF);
setup_adc_ports(NO_ANALOGS);
setup_spi(SPI_SS_DISABLED);
setup_adc_ports(Ent_ADC_Motor | adc_chanel_Cons_Led, VSS_VDD); // set adc input, voltage reference
setup_adc(ADC_CLOCK_DIV_128);
set_adc_channel(entrada_adc_Mot);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //32,7 ms overflow
setup_timer_2(T2_DIV_BY_4 | T2_CLK_INTERNAL,199,1); //50,0 us overflow, 50,0 us interrupt 20Khz
setup_timer_4(T4_DIV_BY_128 | T4_CLK_INTERNAL,255,16); //2,0 ms overflow, 32,7 ms interrupt
setup_timer_6(T6_DIV_BY_16 | T6_CLK_INTERNAL,4,1); //5,0 us overflow, 5,0 us interrupt
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty((int16)duty_0);
set_pwm2_duty((int16)duty_0); zero
// enable_interrupts(INT_EXT); // enable interrupts
enable_interrupts(INT_TIMER1); // enable interrupts
enable_interrupts(INT_TIMER4); // enable interrupts
//enable_interrupts(INT_TIMER6); // enable interrupts
enable_interrupts(INT_RDA); // enable interrupts
enable_interrupts(INT_RDA2); // enable interrupts
enable_interrupts(GLOBAL); // enable the interruptss
} |
Any ideas?
Last edited by ralph79 on Thu Sep 25, 2025 1:55 am; edited 1 time in total |
|
 |
gaugeguy
Joined: 05 Apr 2011 Posts: 348
|
|
Posted: Wed Sep 24, 2025 11:42 am |
|
|
In your #use rs232, use UART1 / UART2 instead of listing the xmit / rcv pins |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19954
|
|
Posted: Thu Sep 25, 2025 1:10 am |
|
|
And, the pin_select statements should be before your #use RS232 lines. One
pair is, the other isn't. |
|
 |
ralph79
Joined: 29 Aug 2007 Posts: 90
|
|
Posted: Thu Sep 25, 2025 1:56 am |
|
|
gaugeguy wrote: | In your #use rs232, use UART1 / UART2 instead of listing the xmit / rcv pins |
I have tested also with UART1 and UART2 even so doesn't work |
|
 |
ralph79
Joined: 29 Aug 2007 Posts: 90
|
|
Posted: Thu Sep 25, 2025 2:12 am |
|
|
Ttelmah wrote: | And, the pin_select statements should be before your #use RS232 lines. One
pair is, the other isn't. |
it's written like this:
Code: | #pin_select U1TX = PIN_C6
#pin_select U1RX = PIN_C7
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=PORT1, errors, restart_wdt) // UART1
#pin_select U2TX = PIN_B6
#pin_select U2RX = PIN_B7
#use rs232(baud= 19200, parity=N, xmit = PIN_B6, rcv = PIN_B7, bits=8, stream=portBT, errors, restart_wdt) /*UART2,*/ |
|
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9583 Location: Greensville,Ontario
|
|
Posted: Thu Sep 25, 2025 5:15 am |
|
|
all the pin_select statements need to be before the #Use rs232...... statements
also, best to NOT have the WDT enabled until AFTER the entire program is 100% working.Then you can decide the proper 'timeout' required for the WDT
and, be sure to have interrupt service routines for all enabled interrupts |
|
 |
|
|
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
|