Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
18F26K22 [solved]
#1
I have spent ages trying to get bootloader working on USART1 of an 18F26K22. I have had no problems with other chips from the 18F family but this one has been a major headache.
After 2 days of fiddling i finally gave up and tried USART2. It worked on USART2 first time, but with errors. It would stop halfway through uploading a program and give a timeout error.
This is with

OSCF 16000000
BAUDRATE 115200

I realise that the Microchip manual gives this a 3% error rate but i have never had any problems with other chips.
I tried reducing the baudrate to 19200 (error rate 0.16) but had the same problems.

I finally fixed it by enabling USE_BRG16 and going back to 115200 (error -0.79%)

Now works perfectly (on USART2). Still nothing on USART1. I know USART1 works ok as i can program it fine using microchip C18 compiler.

Are these chips problematic or is there something i am missing?
I am using the latest version 3.0.0 of the bootloader software and my config settings are

config FOSC = INTIO67
config WDTEN = OFF
config BOREN = OFF
config PWRTEN = ON
config MCLRE = EXTMCLR
config LVP = OFF
config HFOFST = OFF
config PRICLKEN = OFF
config FCMEN = OFF
config CCP3MX = PORTB5
config XINST = OFF
config IESO = OFF

Has anyone got the bootloader working on USART1?

Thanks
Reply
#2
Please show us the code that configures the uart1 pins to be digital.
Reply
#3
(2011-07-07, 14:46:32)Mikael Gustafsson Wrote: Please show us the code that configures the uart1 pins to be digital.

Mikael
I tried nuerous things to try and make it work. Like turning off comparators etc. The final code below probably has stuff that can be removed

;------------------------------------------------------------------------------
; User specific entry code go here
;------------------------------------------------------------------------------

;----------------------------------------------------------------------
; Make uart pins digital
;----------------------------------------------------------------------
ifdef ADCON1
;error Do you need to configura uart pins to be digital? If not, remove this line
endif
;movlw b'01100000' ;xxx disable
;movwf ADCON1 ;xxx analog on tx/rx
movlw b'00000000' ;xxx disable
movwf ADCON0 ;xxx analog on tx/rx
movlw b'00000000'
movwf CM1CON0; ; Comparators off
movlw b'00000000'
movwf CM2CON0; ; Comparators off

; Set internal oscillator to 16MHz
movlw b'01110000'
movwf OSCCON
movlw b'00000000'
movwf ANSELA ; DIGITAL
movlw b'00000000'
movwf ANSELB ; DIGITAL
movlw b'00000000'
movwf ANSELC ; DIGITAL
movlw b'10111111'
movwf TRISB ; USART2 - TX Out RX In
movlw b'10111111'
movwf TRISC ; USART1 - TX Out RX In
Reply
#4
That looks as far as I can see. According to table 10-8 in the data sheet you should set tris bit to 1 for both tx and rx, I have never needed to do this before but it might be worth a try. If it still doesn't work I suggest you keep tris bits set to 1 if you try other things.
Reply
#5
(2011-07-07, 22:17:26)Mikael Gustafsson Wrote: That looks as far as I can see. According to table 10-8 in the data sheet you should set tris bit to 1 for both tx and rx, I have never needed to do this before but it might be worth a try. If it still doesn't work I suggest you keep tris bits set to 1 if you try other things.

Mikael
Tried that initially. Worked on USART2 but not on USART1, so i tried setting TX to output but no change. As far as i can see there is no reason why it should not work. It just doesn't.
Although i have it working ok on USART2, i would still like to know why it doesn't work on USART1.
If anyone has a working bootloader for this chip on USART1 perhaps they can send in their code for comparison.
Reply
#6
Do you have the uart working in your application? If so how is the configuration different?
Make two cope snippets in the boot loader to:
1. Toggle led when data is received on rx
2. Send data on tx when a button is pressed or similarly.
This way you can see if bot rx and tx is not working
Reply
#7
(2011-07-08, 11:16:16)Mikael Gustafsson Wrote: Do you have the uart working in your application? If so how is the configuration different?
Make two cope snippets in the boot loader to:
1. Toggle led when data is received on rx
2. Send data on tx when a button is pressed or similarly.
This way you can see if bot rx and tx is not working

Yes UART1 works in my application.
I have tried turning off TXIE just in case that was the problem, but no change.
In bootloader, I can toggle an led on when receive using USART2, but when i try USART1 the led doesn't toggle on, suggesting USART1 not turned on or some other conflict
Reply
#8
Then it shouldn't be to hard figuring out what the problem is.
Send me the application.
Reply
#9
(2011-07-08, 15:51:10)Mikael Gustafsson Wrote: Then it shouldn't be to hard figuring out what the problem is.
Send me the application.

I have attached a zip containing the C source code and the assembler export. The C program just takes characters received on USART1 and sends them back (basic echo) and works fine


Attached Files
.zip   18F26K22 basic.zip (Size: 4.49 KB / Downloads: 29)
Reply
#10
Oh C18 library, the source is available it's some work to go trough them.
Could you read the uart register contents when your C18 application is running?
Reply
#11
I ran your code in MPLAB SIM and looked at these registers:
BAUDCON1, RCSTA1, TXSTA1, SPBRG1, and SPBRGH1.
I found these two differences:
The C code sets TXSTA1.CSRC and RCSTA1.ADDEN. Both should make no difference.
I guess it's something with the oscillator or pin configuration.
Reply
#12
Iam attempting to do exactly the same and have spent quite some time without luck.
Basically my config is the same ie 16MHz internal clock, 115200 baud using UART1.

My initialisation code looks effectively the same as hobbytronics'.

I have put a LED toggle after the RX test and it never gets triggered.

I really need to get his going.

My main application runs fine with serial recieve on UART1, but this did take a bit of work to get going.

CS
Oh and TX does work, I've simply added a debug transmit early in the code and works fine.

CS
Reply
#13
Please start your own thread.

Mikael
Reply
#14
I have used ds30 loader with 18F25K22 with great success.
It is important that you set ANSELC for digital operation if you use USART1.
Don't forget the banksel register BSR before accessing ANSELC.
I have the following code in the .asm-file:

; Make uart pins digital
;----------------------------------------------------------------------
; Enable digital i/o
movlb 0xF ;Set BSR for banked SFRs
movlw b'00000000' ;xxx disable
movwf ANSELC ;xxx analog on tx/rx



Look also in the silikon errata for 18F2Xk22:

The EUSART asynchronous operation has a
probability of 1 in 256 of missing the Start bit edge
for all combinations of BRGH and BRG16 values,
other than BRGH = 1, BRG16 = 1.
Work around
Set BRGH = 1, and BRG16 = 1

Reply
#15
(2012-03-25, 21:26:04)ghu Wrote: Look also in the silikon errata for 18F2Xk22:

The EUSART asynchronous operation has a
probability of 1 in 256 of missing the Start bit edge
for all combinations of BRGH and BRG16 values,
other than BRGH = 1, BRG16 = 1.
Work around
Set BRGH = 1, and BRG16 = 1

Hello All
Thanks ghu!
I have been having issues with the ds30 loader writing the complete file.
It would just stop half way about 70% of the time.
This info on the silicon errata was the problem.
All fixed thanks.
Tom
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)