This is a back burner project. I have a limited supply of 18F26K80 ( need 12 bit analog and dual usart). So I thought I would try a newer chip and selected 16F17145.
When I first got them I was also trying to get the timer1 external clock osc xtal to work and i noticed the uart Xmit works just fine but the receive would not receive my commands. The program was working fine on the 18F26K80.
I did some troubleshooting and modified the usart.h file ( usart.h has certained gained a lot of weight since I last worked on it). Usart still does not receive. xmits fine.
I think it has to do with naming RC1REG or RCREG1.
I continued to mess with things and changed the 16F17145.dat file .
Also the pps doesn't have RC1 in nor Rx and it has to be modified outside of pps program.
Yes I have dug myself a hole and am floudering in it.
There are other problems but let's figure out first the serial usart. the clock xtal mostly don't work some times it runs. Don't worry I have resigned my self to external DS3231.
I see no demos for serial com except in the help. Search nothing of this family.
Partly solved.
First the pps program does not have RX1 and RX2. It does have RX but RXpps does not exist.
default is RX1 on RB5 so did leave the bad line out and that worked.
additionally I tried just adding the 1 to RX1PPS and that worked too.
Second , after reading the pdf for PIC16F17xxx it needs some bits set .
CREN = 1
SYNC =0
SPEN =1
This is the test program
#chip 16F17145, 8
#option explicit
// PIC PPS Tool version: 0.0.6.5
#startup InitPPS, 85
#define PPSToolPart 16F17145
// PIC PPS Tool version: 0.0.6.5
Sub InitPPS
UNLOCKPPS
// Module: Error
RB6PPS = 0x0013 // TX1 > RB6
// Module: EUSART
RX1PPS = 0x000D // RB5 > RX
LOCKPPS
End Sub
// Add this code segment to your GCBASIC source program
Dim enter as string
enter = 13, 10 '' create a string to concantenate for CRLF
'InitUSART
'USB stick serial comm
#define USART_BAUD_RATE 9600
#define USART_DELAY off
#define USART_TX_BLOCKING
'#define USART_BLOCKINGj
'Serial to PC terminal
'Set pin directions
'USB stick adapter Serial Port
Dir PORTb.5 in 'USART 1 Rx Pin
Dir PORTb.6 out 'USART 1 Tx Pin
Dim comport, inchar as Byte
CREN = 1
SYNC =0
SPEN =1
Begin:
If USARTHasData Then
HSerReceive(InChar)
HSerSend HEX(InChar) 'send back char to UART
End if
wait 50 ms
Goto begin
So tomorrow, I will try the second usart. Only took months and 2 more hours.
Problem solved but still needs to be fixed.
Thanks Evan
BR
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Let me resolve the issue in the usart.h before trying USART2. USART2 will not work. So, please wait.
I know why this is happening. And, it is a silly testing error. The 16F17126 is a chip of this family. However, I have only tested sending data and I have failed to test incoming data.
The fix will be relatively simply but I need make the change and test.
The test program we should use should look like your program. This is a clean program using minimal ram. There are two parts to do the same thing ( receive and send byte ). This is required as these use two different methods and both need to be tested.
When this works without the user program corrections ( your bits! ) then we would change from USART1 to USART2.
#chip 16F17145, 8
#option explicit
#startup InitPPS, 85
#define PPSToolPart 16F17145
// PPS is specific to this chip
Sub InitPPS
UNLOCKPPS
// Module: Error
RB6PPS = 0x0013 // TX1 > RB6
// Module: EUSART
RX1PPS = 0x000D // RB5 > RX
LOCKPPS
End Sub
#define USART_BAUD_RATE 9600
#define USART_DELAY OFF
#define USART_BLOCKING
// Main program to receive and sent serial bytes
Do
If USARTHasData Then
// Using USARTHasData will ensure there is incoming data within the serial incoming buffer
// Send back char to USART
HSerSend ( (HSerReceive ) )
// Send back char to USART ensuring that USART1 is selected
// HSerSend ( (HSerReceive, 1 ), 1 )
End if
wait 50 ms
Loop
You can add the following to make this work for you.
// CREN = 1// SYNC =0// SPEN =1
I will use this testing approach for all chips in the future.
Look for a library update soon. :-)
Evan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is a back burner project. I have a limited supply of 18F26K80 ( need 12 bit analog and dual usart). So I thought I would try a newer chip and selected 16F17145.
When I first got them I was also trying to get the timer1 external clock osc xtal to work and i noticed the uart Xmit works just fine but the receive would not receive my commands. The program was working fine on the 18F26K80.
I did some troubleshooting and modified the usart.h file ( usart.h has certained gained a lot of weight since I last worked on it). Usart still does not receive. xmits fine.
I think it has to do with naming RC1REG or RCREG1.
I continued to mess with things and changed the 16F17145.dat file .
Also the pps doesn't have RC1 in nor Rx and it has to be modified outside of pps program.
Yes I have dug myself a hole and am floudering in it.
There are other problems but let's figure out first the serial usart. the clock xtal mostly don't work some times it runs. Don't worry I have resigned my self to external DS3231.
I guess it don't do 2 files?
Are there any demos for this specific chipfamily? i cannot tell as i am on my fone.
If no demos then cut the code down to absolute minimum and then examine the ASM. Repost simple program.
Advice. Do not change DAT. Changing DAT has huge implications beyond GCBASIC.
Evan
I see no demos for serial com except in the help. Search nothing of this family.
Partly solved.
First the pps program does not have RX1 and RX2. It does have RX but RXpps does not exist.
default is RX1 on RB5 so did leave the bad line out and that worked.
additionally I tried just adding the 1 to RX1PPS and that worked too.
Second , after reading the pdf for PIC16F17xxx it needs some bits set .
This is the test program
So tomorrow, I will try the second usart. Only took months and 2 more hours.
Problem solved but still needs to be fixed.
Thanks Evan
BR
Mike
Let me resolve the issue in the usart.h before trying USART2. USART2 will not work. So, please wait.
I know why this is happening. And, it is a silly testing error. The 16F17126 is a chip of this family. However, I have only tested sending data and I have failed to test incoming data.
The fix will be relatively simply but I need make the change and test.
The test program we should use should look like your program. This is a clean program using minimal ram. There are two parts to do the same thing ( receive and send byte ). This is required as these use two different methods and both need to be tested.
When this works without the user program corrections ( your bits! ) then we would change from USART1 to USART2.
You can add the following to make this work for you.
I will use this testing approach for all chips in the future.
Look for a library update soon. :-)
Evan
You can try this. Remove the additional bits from user program.
Revert USART.H and then add the following at line 161. ( The USART.H I am using is dated 13/02/2024 on line 100 ).
All this does is normalise this chip to ensure the naming in the D AT file is consistent with the library.