View previous topic :: View next topic |
Author |
Message |
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
Migration from 16F15223 to 16F18323 |
Posted: Thu Oct 12, 2023 1:11 pm |
|
|
Code: | //!#include <16F15223.h> // device file
#include <16F18323.h> // device file
#use delay(internal = 32MHZ)
#fuses PUT, NOWDT // 16F18323
//!#fuses PUT_16MS, NOWDT // 16F15223
#use rs232(baud=28800,parity=N,xmit=PIN_C4,bits=8,stream=VT)
#define TEN_MS 0xD8EF // 65535 - 10000 = 55535, 1 MHz/10000 = 100 Hz
void timer1_ISR(void); // prototype
unsigned int16 FREE_RUNNING_TIMER = 0;
void main(void)
{
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); // clocked @ Fosc/(4*8) = 1 MHz
enable_interrupts(INT_TIMER1); // enable timer interrupts
enable_interrupts(global); // enable all interrupts
set_timer1(TEN_MS); // initialize timer for 10 ms interrupts
disable_interrupts(GLOBAL);
fprintf(VT, "Hello World!!\r\n");
enable_interrupts(GLOBAL);
while(TRUE)
{
if(FREE_RUNNING_TIMER > 100)
{
disable_interrupts(GLOBAL);
fprintf(VT, "Hello World??\r\n");
enable_interrupts(GLOBAL);
FREE_RUNNING_TIMER = 0;
}
}
}
#INT_TIMER1
void timer1_ISR(void)
{
clear_interrupt(INT_TIMER1);
FREE_RUNNING_TIMER++;
set_timer1(TEN_MS);
} |
Compiler is 5.116. The code above works with the 15223 with one Hello World!! and repeated Hello World?? once each second thereafter. On the 18323, I only get the first Hello World!! after programming and no Hello World??. If I start up w/o programming, I get nothing from the VT stream. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Oct 12, 2023 2:29 pm |
|
|
hmmmm.does that PIC have PPS pins ?? Ones where YOU can program what pin is used for which peripheral ???? |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Thu Oct 12, 2023 2:30 pm |
|
|
Yes, sir. I tried:
#pin_select TX1 = PIN_C4
but no change. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Oct 12, 2023 2:45 pm |
|
|
hmm, after #fuses and before #use rs232(....) ? Order is kinda important....
also wondering if you have to 'PPS' BOTH TX and RX pins to make compiler 'happy' ?
I don't use these new fangled PICs just thinking of weird stuff that can trip you up... |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Thu Oct 12, 2023 2:52 pm |
|
|
Yes, after fuses and before rs232. I just tried
Code: | #pin_select TX1=PIN_C4
#pin_select RX1=PIN_C5
#use rs232(baud=28800,parity=N,xmit=PIN_C4,bits=8,stream=VT) |
and got nothing out of VT. Any idea why I only get something after programming but nothing if I start up with an external supply? The voltage at the chip measures good. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Fri Oct 13, 2023 6:01 am |
|
|
Look at the top of the forum at the sticky about how to use PPS.
You are not using the hardware port. You are setting up a software serial.
Use the UART1 syntax shown in the sticky.
On the wake up, look at the rise time of your supply. How is the MCLR
pin wired?. The programmer takes control of this pin. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Fri Oct 13, 2023 9:55 am |
|
|
Thank you for the advice. I've removed the timer interrupt to simplify the code. Here is the latest:
Code: |
#include <16F18323.h> // device file
#fuses PUT, NOWDT
#use delay(internal=32MHZ)
#pin_select U1TX=PIN_C4
#use rs232(UART1,baud=28800,parity=N,xmit=PIN_C4,bits=8,errors,stream=VT)
void main(void)
{
disable_interrupts(GLOBAL);
fprintf(VT, "Hello World!!\r\n");
enable_interrupts(GLOBAL);
while(TRUE)
{
disable_interrupts(GLOBAL);
fprintf(VT, "Hello World??\r\n");
enable_interrupts(GLOBAL);
delay_ms(1000);
}
} |
It appears now to display part of the second message and then hangs at the delay function:
Code: |
Hello World!!
Hello World?ΓΏ
|
The MCLR pin is connected to the junction of a 10k resistor and 0.1uF capacitor. The resistor is connected to +5V and the capacitor to ground. |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Fri Oct 13, 2023 10:02 am |
|
|
You are not following the advice you have been given. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Fri Oct 13, 2023 11:00 am |
|
|
I tried specifying the RX pin as well but still get the same behavior.
Code: |
#include <16F18323.h>
#fuses PUT, NOWDT
#use delay(internal=32MHZ)
#pin_select U1TX=PIN_C4
#pin_select U1RX=PIN_C5
#use rs232(UART1,baud=28800,parity=N,bits=8,errors,stream=VT)
|
|
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Fri Oct 13, 2023 12:43 pm |
|
|
gaugeguy, forgive me, but can you be more specific? |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Fri Oct 13, 2023 2:09 pm |
|
|
If you have removed your interrupt routines, why are you enabling interrupts? |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Fri Oct 13, 2023 2:13 pm |
|
|
I disable the interrupts before sending data to the VT stream and then re-enable after sending. In the past, that has helped with cleaning up a garbled transmission. I hope to add the timer back in after the rs-232 is working. |
|
|
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Mon Oct 16, 2023 3:44 pm |
|
|
I used the statement:
in another program and now this program works as originally posted. Does anyone know why? I'm using the ICD-U64 programmer. |
|
|
|