This issue was resolved when the serial library was updated.
I would install the latest build and test. If this fails then let me know. Then, see if you transfer the serial library back to your old version of the compiler. It may fail on compilation as many more core functions will have been added to library, but, it may work.
Or, use software serial on that old version of the compiler.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'UART needed for Board 1
#define UART1_Rec PORTC.7
#define UART1_TX PORTC.6
'#define USART1_BAUD_RATE 115200
'#define USART1_BLOCKING
#define USART_BAUD_RATE 115200
#define USART_BLOCKING 'USART routines wait until data can be sent or received.
And, you have way too much code. This really confuses me. You only need two lines of code for the USART.
You have:
;Chip Settings#chip 18F4550,48
#config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, LVP=OFF, MCLRE=ON ;OFF
'UART needed for Board 1
//! Not needed
// #define UART1_Rec PORTC.7
//#define UART1_TX PORTC.6
'#define USART1_BAUD_RATE 115200
'#define USART1_BLOCKING
#define USART_BAUD_RATE 115200
#define USART_BLOCKING 'USART routines wait until data can be sent or received.
//! Not needed
Dir UART1_Rec In
Dir UART1_TX Out
//! Not needed
'UART needed for Board 2
#define UART2_Rec PORTa.1
#define UART2_TX PORTa.0
//! Not needed
'#define USART2_BAUD_RATE 115200
'#define USART2_BLOCKING
//! Not needed
Dir UART2_Rec In
Dir UART2_TX Out
What is needed:
;Chip Settings#chip 18F4550,48
#config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, LVP=OFF, MCLRE=ON ;OFF
'UART needed for Board 1
#define USART_BAUD_RATE 115200
#define USART_BLOCKING 'USART routines wait until data can be sent or received.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using version (GCBASIC 0.99.01 2022-01-27 (Windows 64 bit) : Build 1073) with an 18F4550.
I'm trying to use both Hardware UART, 1 and UART, 2. I wrote this simple program:
;Chip Settings
#chip 18F4550,48
#config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, LVP=OFF, MCLRE=ON ;OFF
'**********
'UART needed for Board 1
#define UART1_Rec PORTC.7
#define UART1_TX PORTC.6
#define USART1_BAUD_RATE 115200
#define USART1_BLOCKING
'UART needed for Board 2
#define UART2_Rec PORTa.1
#define UART2_TX PORTa.0
#define USART2_BAUD_RATE 115200
#define USART2_BLOCKING
'**********
Do_Again:
'This works
comport = 1
HSerPrint "UART 1", 1
HSerSend 13, 1
HSerSend 10, 1
'*******
'This does NOT work
comport = 2
HSerPrint "UART 2", 2
HSerSend 13, 2
HSerSend 10, 2
wait 2 s
goto Do_Again
'**********
UART,1 works but UART,2 does not.
What am I doing wrong?
By works I mean the program sends the message to my cell phone.
This should have been put in the HELP forum. Can someone who knows how move it there.
This issue was resolved when the serial library was updated.
I would install the latest build and test. If this fails then let me know. Then, see if you transfer the serial library back to your old version of the compiler. It may fail on compilation as many more core functions will have been added to library, but, it may work.
Or, use software serial on that old version of the compiler.
Or, I can compile your test program and post the HEX for testing.
This time I compiled it using GC Studio.
Program compiled by GCBASIC (2025.02.15 (Windows 64 bit) : Build 1465)
The results were the same: UART 1 works but UART 2 does not.
Any suggestions?
Can you post a test program ? I can have a look and see what is happening.
This my program:
;Chip Settings
#chip 18F4550,48
#config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, LVP=OFF, MCLRE=ON ;OFF
'****
'UART needed for Board 1
#define UART1_Rec PORTC.7
#define UART1_TX PORTC.6
#define USART_BAUD_RATE 115200
#define USART_BLOCKING
'UART needed for Board 2
#define UART2_Rec PORTa.1
#define UART2_TX PORTa.0
Dir UART2_Rec In
Dir UART2_TX Out
'****
Do_Again:
'This works
comport = 1
HSerPrint "UART 1", 1
HSerSend 13, 1
HSerSend 10, 1
HSerSend 72, 1 ;H
HSerSend 69, 1 ;E
HSerSend 76, 1 ;L
HSerSend 76, 1 ;L
HSerSend 79, 1 ;O
HSerSend 13, 1
HSerSend 10, 1
'*
'This does NOT work
comport = 2
HSerPrint "UART 2", 2
HSerSend 13, 2
HSerSend 10, 2
HSerSend 72, 2 ;H
HSerSend 69, 2 ;E
HSerSend 76, 2 ;L
HSerSend 80, 2 ;P
HSerSend 33, 2 ;!
HSerSend 13, 2
HSerSend 10, 2
wait 2 s
goto Do_Again
'****
There is only one USART on that chip. Have a look in PICINFO. If you want a second USART then use the software USART for USART2.
This should work, a simpler program.
The following has USART2_BAUD_RATE defined and the compiler issues a warning.
The configuration of a USART depends on ONEOF(USART_BAUD_RATE,USART1_BAUD_RATE,USART2_BAUD_RATE,USART3_BAUD_RATE,USART4_BAUD_RATE,USART5_BAUD_RATE)
Evan
I changed it to this:
'UART needed for Board 1
#define UART1_Rec PORTC.7
#define UART1_TX PORTC.6
'#define USART1_BAUD_RATE 115200
'#define USART1_BLOCKING
#define USART_BAUD_RATE 115200
#define USART_BLOCKING 'USART routines wait until data can be sent or received.
Dir UART1_Rec In
Dir UART1_TX Out
'UART needed for Board 2
#define UART2_Rec PORTa.1
#define UART2_TX PORTa.0
'#define USART2_BAUD_RATE 115200
'#define USART2_BLOCKING
Dir UART2_Rec In
Dir UART2_TX Out
Now I see both the "UART 1", 1 and "UART 2", 2 messages coming from the UART Board 1.
Still no response from Board 2.
There is NO USART 2. There is only one USART. I you want a second USART use software serial for the second port see https://gcbasic.sourceforge.io/help/_rs232_software_overview_optimised.html
And, you have way too much code. This really confuses me. You only need two lines of code for the USART.
You have:
What is needed: