I just compiled a gcb code for 18F47Q10 and the HW USART i'm using ,stopped functioning. This is the compiler output:
14:57:32 G+Stool started with parameter 'hex' -> processing C:\GCstudio\G+Stools\makeHEX.bat
Source-File = F:\EBAY\other\Pic_projects\CPC_SERIAL_PORT\Serial port ii\18f47q10_7d_WPUD_ACTIVATE_serial1.gcb
Target-File = F:\EBAY\other\Pic_projects\CPC_SERIAL_PORT\Serial port ii\18f47q10_7d_WPUD_ACTIVATE_serial1.hex
Compiler Version: 2024.12.15 (Windows 64 bit) : Build 1447) Program Memory: 64740/65536 words (98,79%) RAM: 3159/3359 bytes (94,05%) OSC: HFINTOSC_1MHZ, 64Mhz (Internal oscillator) Chip: 18F47Q10
Duration: 11.4 Seconds.
And these are the declarations of HW USART in the code:
` #define USART2_BAUD_RATE 1065600
#define USART2_DELAY 0 ms
#define USART_DELAY 0 ms
#define USART2_BLOCKING
#define SerInPort PORTB.1
#define SerOutPort PORTB.2
OK. Can you create a program that does Serial Buffer loopback. Use the same ports as in your program, pps etc. One that should work. Like the example in the HELP for the Serial Buffer.
If that does not work for you, post here, I will need to test to figure out what is happening.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using pic uart to communicate with a ch376 usb host module, testing communication (send a sequence of 4 bytes) doesn't respond at all, it's like as if nothing is sent and/or nothing is received back.
Now, i also made further tests, using a usb2serial cable and a terminal windows program, it seems that hardware usart receives bytes without problem, but it can't send any byte!
So probably the problem must be somewhere in the hsersend routine?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the "test routine" is actually a basic program in Amstrad CPC that communicate with PIC chip through I/O requests at specific ports (these are configured using various computer signals and the CLC's of PIC). uart is connected with a serial cable to a pc where a small terminal program is running and i'm able to exchange messages.
Anything i sent from pc to Amstrad is received ok, so the ring buffer and hserreceive routine must work ok, but when i try to send a byte from Amstrad to pc, nothing is received...
Perhaps, you want to make a small gcb program that will send bytes to serial port in a loop then?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#chip 18F47q10, 64#option explicit#startup InitPPS, 85#define PPSToolPart 18f47q10#define USART2_BAUD_RATE 1115200#define STRINGSIZE 15#define BUFFER_SIZE 2900#define USART2_DELAY 0 ms#define USART_DELAY 0 ms#define USART2_BLOCKING#define SerInPort PORTB.1#define SerOutPort PORTB.2SubInitPPSUNLOCKPPSRX2PPS=0x0009'RB1 > RX2RB2PPS=0x000B'TX2 > RB2LOCKPPSEndSub'USART settings;#define USART_BAUD_RATE 115200 'Initializes USART port with 9600 baud'#define USART_BLOCKING 'Bothoftheseblockingstatementswill;#define USART_TX_BLOCKING ' wait for tx register to be empty' use only one of the two constants;#define USART_DELAY OFF'Main loopDo'Send PORTB value through USARTHSerSend65,2Wait200ms'probably not necessary with blocking statementLoop
This should send to uart port 'A' character 5 times/second. I powered board with PIC, connect Tx,Rx, Gnd , but unfortunately i don't get anything on PC terminal window...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unfortunately i get nothing on PC terminal with first-start-sample.gcb too....
Well, it's not too urgent ,but i will need to compile an updated code soon.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Used the basic test program to send data, see above. This key to this test in minimal code and the use of HSerSend 65,2. HSerSend essentially sets the output register to 65. This failed.
Examine at ASM. Examined the HSerSend routine in the generated ASM. Looks good - this waits for USART data flag to be set ( TX2IF ) then sets TX2REG = SerData.
No errant registers, or register bits. Uses TX2, so assume that is this good.
Examine the CDF for the test program. Search for SPBRGL_TEMP2, open the CDF and do a search.
Not good...
Shows that the final result is zero.
FINAL/CONSTANT :SPBRGL_TEMP2 0
The CDF shows SCRIPT/AddConstant: Line 705 SPBRGL_TEMP2 0 C:\GCstudio\gcbasic\INCLUDE\LOWLEVEL\usart.h so something in USART is set the contsant SPBRGL_TEMP2 to zero. That is not correct.
Note: Line numbers may vary
Open USART.H. Examine line 705.
SPBRG_TEMP2 is the basis to set SPBRGL_TEMP2, therefore SPBRG_TEMP2 is zero before the calc.
There is two tests in the part of the USART If Bit(BAUDCON2_BRG16) and If Bit(U2BRGS).
Open PICINFO, search for the bits shown above ... niether exist. Arghhh.
BAUDCON2_BRG16 must have worked in the past... and, there is a register bit called BAUD2CON_BRG16... The DAT file controls all the register.bits... so, something has changed as this WAS working in the past.
Using SVN ( the SourceForge respository is an SVN respository ). Compare the 18f47q10.dat file.
RESULT - BAUDCON2_BRG16 is missing in the current release compared to the current release.
The root cause is the DAT file has changed.
RULES ON DAT FILES
The DAT file generation process to generate the DAT is fully automated. There is NO manual intervention.
The DAT file generation process uses XML provided from MPLAB-X. . There is NO editing. Microchip make corrections to address, bit registers etc etc. these will include corrections from the greater Microchip community.
The XLM is the master source. The outcome of the DAT file generation process is master.
There are 1416 dat files and visual inspection is IMPOSSIBLE.
So, the DAT is the DAT and we NEVER edit.
We need to change the libraries if the DAT file changes.
RESOLUTION
a. Change the script section in USART.H to cater for the DAT change.
From If Bit(BAUDCON2_BRG16) Then
to
If Bit(BAUDCON2_BRG16) or Bit(BAUD2CON_BRG16) Then
b. Add an inspection that the constant SPBRG_TEMP2 is zero. Is Zero issue a warning.
c. Replicate this change to all USART 1,3,4 & 5 sections.
d. Examine the ASM
ASM is correct and the registers are no longer set to zero.
An idea. I could issue a DIFF file for all the DAT files for changes to the DAT files. See attached the DIFF for this specific Q10.
But, to be honest there are so many changes it is hard to figure out what is what and you would need the DIFF tools ( part of SVN ).
This shows that BAUDCON2_BRG16 was removed at the last DAT file regen.
Anything is RED is deleted, GREEN is added. So, you can see the additions to the DAT file. These improvements would be missed if we did not autogenerate the DAT file.
No easy answer here. Users needs to test projects as we continually improve GCBASIC.
Anyone got any constructive thoughts ? It is very easy to be critical of the process but I will happily discuss and implement any and all improvements.
With the new USART.h everything works ok! So it was Microchip's fault after all... :-)
Thanks again Evan for the quick resolve, Merry Christmas and a productive-creative new year!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just compiled a gcb code for 18F47Q10 and the HW USART i'm using ,stopped functioning. This is the compiler output:
14:57:32 G+Stool started with parameter 'hex' -> processing C:\GCstudio\G+Stools\makeHEX.bat
Source-File = F:\EBAY\other\Pic_projects\CPC_SERIAL_PORT\Serial port ii\18f47q10_7d_WPUD_ACTIVATE_serial1.gcb
Target-File = F:\EBAY\other\Pic_projects\CPC_SERIAL_PORT\Serial port ii\18f47q10_7d_WPUD_ACTIVATE_serial1.hex
Compiler Version: 2024.12.15 (Windows 64 bit) : Build 1447) Program Memory: 64740/65536 words (98,79%) RAM: 3159/3359 bytes (94,05%) OSC: HFINTOSC_1MHZ, 64Mhz (Internal oscillator) Chip: 18F47Q10
Duration: 11.4 Seconds.
And these are the declarations of HW USART in the code:
On Interrupt UsartRX2Ready Call readUSART
With previous compiler everything worked ok, so definetely something is wrong with the new compiler regarding the HW USART.
Can you post your GCBASIC source ? The segments here mean I cannot test compile.
A contributor may have caused a double read in the receive routine.
Please try attached.
No, i'm afraid i doesn't work. Attached file is the gcb source code.
OK. Can you create a program that does Serial Buffer loopback. Use the same ports as in your program, pps etc. One that should work. Like the example in the HELP for the Serial Buffer.
If that does not work for you, post here, I will need to test to figure out what is happening.
I'm using pic uart to communicate with a ch376 usb host module, testing communication (send a sequence of 4 bytes) doesn't respond at all, it's like as if nothing is sent and/or nothing is received back.
Now, i also made further tests, using a usb2serial cable and a terminal windows program, it seems that hardware usart receives bytes without problem, but it can't send any byte!
So probably the problem must be somewhere in the hsersend routine?
Please write the test routine And, I will examine here.
the "test routine" is actually a basic program in Amstrad CPC that communicate with PIC chip through I/O requests at specific ports (these are configured using various computer signals and the CLC's of PIC). uart is connected with a serial cable to a pc where a small terminal program is running and i'm able to exchange messages.
Anything i sent from pc to Amstrad is received ok, so the ring buffer and hserreceive routine must work ok, but when i try to send a byte from Amstrad to pc, nothing is received...
Perhaps, you want to make a small gcb program that will send bytes to serial port in a loop then?
Yes, take the Serial Buffer demo from the Help, change chip, set pps as your settings.
Does that work? open a terminal does it return the characters? if not, send me this test ( newly created) program.
Last edit: Anobium 2024-12-23
OK, I made this smal testing code:
This should send to uart port 'A' character 5 times/second. I powered board with PIC, connect Tx,Rx, Gnd , but unfortunately i don't get anything on PC terminal window...
Excellent. Thank you. I will use yours.
How urgent is this ? it is Christmas soon.
I just wrote a full test program.
Unfortunately i get nothing on PC terminal with first-start-sample.gcb too....
Well, it's not too urgent ,but i will need to compile an updated code soon.
:-)
I will resolve ASAP! I promise.
Thanks evan, i really appreciate your help and concern! :-)
where can i find previous versions of cow basic? Maybe i could pinpoint exactly when this bug occurs...
It will take me more time to roll back the USART.H.
THANK YOU!
I have found the root cause. Microchip have renamed some of the USART2 register bits. So, when the DAT files were regen'ed the new names are used.
I have resolved here. Just testing.
This is resolves the issue.
I have added a check to ensure the baud rate calculation is completed - would now issue an error the baud rate calculation is zero.
Test program used
This is how I diagnosed at resolved.
HSerSend 65,2
.HSerSend
essentially sets the output register to 65. This failed.HSerSend
routine in the generated ASM. Looks good - this waits for USART data flag to be set ( TX2IF ) then sets TX2REG = SerData.No errant registers, or register bits. Uses TX2, so assume that is this good.
Check that INITUSART is being called. It is, so assume that is this good.
Ah ah... this is not correct. Why is the SPBRG2, SPBRGH2 regiser being set to Zero when they control the baudrate!!!
Not good...
Shows that the final result is zero.
FINAL/CONSTANT :SPBRGL_TEMP2 0
The CDF shows
SCRIPT/AddConstant: Line 705 SPBRGL_TEMP2 0 C:\GCstudio\gcbasic\INCLUDE\LOWLEVEL\usart.h
so something in USART is set the contsant SPBRGL_TEMP2 to zero. That is not correct.Note: Line numbers may vary
SPBRG_TEMP2 is the basis to set SPBRGL_TEMP2, therefore SPBRG_TEMP2 is zero before the calc.
There is two tests in the part of the USART
If Bit(BAUDCON2_BRG16)
andIf Bit(U2BRGS)
.Open PICINFO, search for the bits shown above ... niether exist. Arghhh.
BAUDCON2_BRG16
must have worked in the past... and, there is a register bit calledBAUD2CON_BRG16
... The DAT file controls all the register.bits... so, something has changed as this WAS working in the past.RESULT - BAUDCON2_BRG16 is missing in the current release compared to the current release.
The root cause is the DAT file has changed.
RULES ON DAT FILES
The DAT file generation process to generate the DAT is fully automated. There is NO manual intervention.
The DAT file generation process uses XML provided from MPLAB-X. . There is NO editing. Microchip make corrections to address, bit registers etc etc. these will include corrections from the greater Microchip community.
The XLM is the master source. The outcome of the DAT file generation process is master.
There are 1416 dat files and visual inspection is IMPOSSIBLE.
So, the DAT is the DAT and we NEVER edit.
We need to change the libraries if the DAT file changes.
RESOLUTION
a. Change the script section in USART.H to cater for the DAT change.
From
If Bit(BAUDCON2_BRG16) Then
to
If Bit(BAUDCON2_BRG16) or Bit(BAUD2CON_BRG16) Then
b. Add an inspection that the constant SPBRG_TEMP2 is zero. Is Zero issue a warning.
c. Replicate this change to all USART 1,3,4 & 5 sections.
d. Examine the ASM
ASM is correct and the registers are no longer set to zero.
e. Test on real silicon
Works.
Resolved.
Last edit: Anobium 2024-12-24
An idea. I could issue a DIFF file for all the DAT files for changes to the DAT files. See attached the DIFF for this specific Q10.
But, to be honest there are so many changes it is hard to figure out what is what and you would need the DIFF tools ( part of SVN ).
This shows that BAUDCON2_BRG16 was removed at the last DAT file regen.
Anything is RED is deleted, GREEN is added. So, you can see the additions to the DAT file. These improvements would be missed if we did not autogenerate the DAT file.
No easy answer here. Users needs to test projects as we continually improve GCBASIC.
Anyone got any constructive thoughts ? It is very easy to be critical of the process but I will happily discuss and implement any and all improvements.
Last edit: Anobium 2024-12-24
Latest USART.h
Download by clicking the link above.
With the new USART.h everything works ok! So it was Microchip's fault after all... :-)
Thanks again Evan for the quick resolve, Merry Christmas and a productive-creative new year!
MERRY CHRISTMAS!!!
Great news.
We cannot blame anyone. We just learn all the time. :-)
I have added the new USART.H to the release code. Thank you helping, again!