News:

Let's find out together what makes a PIC Tick!

Main Menu

HRSOut1 "Hello World" --- Terminal not receiving.

Started by JackB, Dec 10, 2024, 01:44 AM

Previous topic - Next topic

JackB

Hello everyone,

Currently learning basic from Proton
I wrote a simple program to test the USART on PIC18F14K22 (Pin PORTB.7 Tx)

This PIC has been tested and it's working well with other compiler

the terminal show the status for the USART but nothing is received at the terminal window,
only random characters when powering ON/OFF the proto board.

Please advise what I'm doing wrong.

Thanks to all.

Device = 18F14K22       
Declare Xtal = 64
Declare Hserial_Baud = 9600
Declare HRSOut1_Pin  PORTB.7 ' Tell the compiler what pin to use for the USART TX
HRSOut1 "Hello World"



flosigud

Hi and welcome.
You have to set the fuses. To do that you use the Fuse configurator that used be within the installation but I can't find it there anymore. Positron Studio has it though. It is one of two alternative IDE's available.

JackB

 I see, but the same PIC is working fine with a GCBasic code,
I uploaded GCBasic code, and it's work fine
I upload Proton, and the terminal received no data.

flosigud


JackB

Hello friend,

from the example code found on page 213 "Positron 8 Basic Compiler Manual", there's no mention on how to
setup fuse.

Also the GCBasic fuses are automaticly setup when compiling. no need to setup outside unless you have a certain function that need
the OSC or WDT changes.

maybe I'm missing something here, did you wrote any code in Proton about UART.

Let me know if you have sample code that can work.


Example 1
 Device = 16F1829
Declare Xtal = 20 ' Tell the compiler the device will be operating at 20MHz
 Declare Hserial_Baud = 9600 ' Set Baud rate to 9600 for HRsin and HRsout
Dim bVar1 as Byte
Dim wWrd as Word
 Dim dDwd as Dword

 HRsout "Hello World" ' Display the text "Hello World"
 HRsout "Var1= ", Dec bVar1 ' Display the decimal value of bVar1
 HRsout "Var1= ", Hex bVar1 ' Display the hexadecimal value of bVar1
 HRsout "Var1= ", Bin bVar1 ' Display the binary value of bVar1
 HRsout "Dwd= ", Hex6 dDwd ' Display 6 hex characters of a Dword variable


normnet

#5
  Recommend first blinking an LED to verify PIC working OK.  Fuses required.

  Working code for a 18F452. Adjust accordingly from PIC data sheet:
     RCSTA.7 = 1   ' SERIAL PORT ENABLED
  RCSTA.4 = 1   ' RX ENABLE
  TXSTA.2 = 0   ' BRGH = BIT 2 OF TXSTA  1 = HIGH SPEED  %00100110
  TXSTA.4 = 0   ' SYNC = BIT 4 OF TXSTA  0 = ASYNCHRONOUS 'SYNC IS BIT 4 OF TXSTA
  TXSTA.5 = 1   ' TX ENABLE
  'SPBRG = 21  ' 40 MHz       10 MHz CRYSTAL
  'SPBRG = 23  ' 44.2368 MHz  11.0592 MHz BAUD RATE CRYSTAL FOR 0 TIMING ERRORS
  SPBRG = 207  ' 4 MHz 300 baud  4 MHz CRYSTAL    BRGH = 0
  'SPBRG = 12  ' 4 MHz 19200 baud  4 MHz CRYSTAL  BRGH = 1

  HSerOut["START",13]

flosigud

Here are the fuse settings I use.

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Config_Start
  FOSC = INTIO7   ;Internal oscillator block, CLKOUT function on OSC2
  PLLCFG = On   ;Oscillator multiplied by 4
  PRICLKEN = On   ;Primary clock enabled
  FCMEN = OFF   ;Fail-Safe Clock Monitor disabled
  IESO = OFF   ;Oscillator Switchover mode disabled
  PWRTEN = On   ;Power up timer enabled
  BOREN = SBORDIS   ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 190   ;VBOR set to 1.90 V nominal
  WDTEN = OFF   ;Watch dog timer is always disabled. SWDTEN has no effect.
  WDTPS = 32768   ;1:32768
  CCP2MX = PORTB3   ;CCP2 input/output is multiplexed with RB3
  PBADEN = OFF   ;PORTB<5:0> pins are configured as digital I/O on Reset
  CCP3MX = PORTB5   ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST = OFF   ;HFINTOSC output and ready status are delayed by the oscillator stable status
  T3CMX = PORTC0   ;T3CKI is on RC0
  P2BMX = PORTB5   ;P2B is on RB5
  MCLRE = EXTMCLR   ;MCLR pin enabled, RE3 input pin disabled
  STVREN = On   ;Stack full/underflow will cause Reset
  LVP = OFF   ;Single-Supply ICSP disabled
  XINST = OFF   ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF   ;Disabled
  Cp0 = OFF   ;Block 0 (000800-001FFFh) not code-protected
  CP1 = OFF   ;Block 1 (002000-003FFFh) not code-protected
  CP2 = OFF   ;Block 2 (004000-005FFFh) not code-protected
  CP3 = OFF   ;Block 3 (006000-007FFFh) not code-protected
  CPB = OFF   ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF   ;Data EEPROM not code-protected
  WRT0 = OFF   ;Block 0 (000800-001FFFh) not write-protected
  WRT1 = OFF   ;Block 1 (002000-003FFFh) not write-protected
  WRT2 = OFF   ;Block 2 (004000-005FFFh) not write-protected
  WRT3 = OFF   ;Block 3 (006000-007FFFh) not write-protected
  WRTC = OFF   ;Configuration registers (300000-3000FFh) not write-protected
  WRTB = OFF   ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF   ;Data EEPROM not write-protected
  EBTR0 = OFF   ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF   ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF   ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF   ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
  EBTRB = OFF   ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

top204

#7
As has been stated above. For 64MHz operation, a device's 4xPLL (Phase Locked Loop) has to be enabled, either in config fuses or with SFR settings in newer devices. The compiler's Declare Xtal directive is purely to tell the compiler what frequency the device will be operating at so it can adjust its internal routine timings, and it does not alter any configs or SFRs.

The compiler's default config fuses set it for an external crystal if the device supports one, so if the 4xPLL is required, it must be enabled in the user code listing. The compiler used to have a PLL declare, however, with the devices that have been available for the past 15 years or so, it is not as straightforward to enable the 4xPLL, so a Declare would have gotten things wrong with some of the very new devices that have multiple, and very different, mechanisms for their internal PLL. i.e. Fuses, SFRs, or sometimes a combination of both, and different PLL multiples so not always 4x.

So if you are setting the Xtal Declare to 64 and using the default fuse configs, you must be using a 16MHz crystal or resonator on your devices, so change the Xtal value to 16. Then when working, alter the config fuses to enable the PLL, then change the Xtal value to 64.



JackB

Thanks Les,

here's a simple loop to verify the USART on Pic chip.
used the default config, exept for the FOSC, PLLEN and OSCCON.
let me know if it's making sense.

Also Thanks for all the comment for helping.

Device = 18F14K22       
Declare Xtal = 16
Config_Start
  FOSC = IRC    ; Internal RC oscillator
  PLLEN = On    ; PLL is under software control
Config_End
OSCCON = $72   
Dim I As Byte
Declare Hserial_Baud = 9600
Declare HRSOut1_Pin = PORTB.7

For I = 0 To 5
    HRSOutLn "0123456789"
Next I


See_Mos

#9
Looks like Jack solved it already except for the XTAL value should be 64 if PLL enabled or 16 without.
Here is my version at 16MHz

This works in ISIS with internal oscillator.  note need to set OSCCON for correct speed.  see page 17 of revision F PDF

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2024 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                              *
'*  Date    : 10/12/2024                                        *
'*  Version : 1.0                                              *
'*  Notes  :                                                  *
'*          :                                                  *
'****************************************************************
Device = 18F14K22
Declare Xtal = 16
Declare Hserial_Baud = 9600
Declare HRSOut1_Pin  PORTB.7 ' Tell the compiler what pin to use for the USART TX

'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config_Start
  FOSC = IRCCLKOUT    ;Internal RC oscillator, CLKOUT function on OSC
  PLLEN = OFF        ;PLL is under software contro
  PCLKEN = ON        ;Primary clock enable
  FCMEN = OFF        ;Fail-Safe Clock Monitor disable
  IESO = OFF          ;Oscillator Switchover mode disable
  PWRTEN = OFF        ;PWRT disable
  BOREN = SBORDIS    ;Brown-out Reset enabled in hardware only (SBOREN is disabled
  BORV = 19          ;VBOR set to 1.9 V nomina
  WDTEN = ON          ;WDT is always enabled. SWDTEN bit has no effect
  WDTPS = 32768      ;1:3276
  HFOFST = ON        ;HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize
  MCLRE = ON          ;MCLR pin enabled, RA3 input pin disable
  STVREN = ON        ;Stack full/underflow will cause Rese
  LVP = ON            ;Single-Supply ICSP enable
  BBSIZ = OFF        ;1kW boot block siz
  XINST = OFF        ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode
  DEBUG = OFF        ;Background debugger disabled, RA0 and RA1 configured as general purpose I/O pin
  CP0 = OFF          ;Block 0 not code-protecte
  CP1 = OFF          ;Block 1 not code-protecte
  CPB = OFF          ;Boot block not code-protecte
  CPD = OFF          ;Data EEPROM not code-protecte
  WRT0 = OFF          ;Block 0 not write-protecte
  WRT1 = OFF          ;Block 1 not write-protecte
  WRTC = OFF          ;Configuration registers not write-protecte
  WRTB = OFF          ;Boot block not write-protecte
  WRTD = OFF          ;Data EEPROM not write-protecte
  EBTR0 = OFF        ;Block 0 not protected from table reads executed in other block
  EBTR1 = OFF        ;Block 1 not protected from table reads executed in other block
  EBTRB = OFF        ;Boot block not protected from table reads executed in other block
Config_End

'**** End of Fuse Configurator Settings ****
'-------------------------------------------------------------------------------


    dIM led aS pORTb.4
    OSCCON = %01110000

    delayms 1000
'
    HRSOut1 "Hello World"
    High LED
    While 1 = 1
    Delayms 500
    Toggle LED
    Wend   

JackB

Well a big thank to you See_Mos

you're spot on !, regarding the OSCCON, with ($72 @ 64Mhz) got random Chr's

I had to use your setup $70 and it's responding well now.

Cheer.