News:

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

Main Menu

PIC 18F46K22 HSerOut problem.

Started by bjkrs, Jul 12, 2022, 01:42 PM

Previous topic - Next topic

bjkrs

hi, I am train myself with PIC 18F46K22 about HSerOut. I want to send "ABCDEF" datas to PC from PIC. when I send "ABCDEF" from PIC, I am reading

hex -----> "5F AF AF 57 D7 17 00"
string --> "_¯¯W×␗<00>"

from terminal.

Do you know what am I doing wrong?

CODES

Device = 18F46K22
Declare Xtal = 10 
Declare Optimiser_Level = 3
Declare Adin_Res 10       
Declare Adin_Tad FRC     
Declare Adin_Stime 50
Declare Hserial_Clear On

Declare LCD_DTPin = PORTD.4
Declare LCD_RSPin = PORTD.0
Declare LCD_ENPin = PORTD.1
Declare LCD_Interface = 4    
Declare LCD_Lines = 2  
Declare LCD_Type = Alphanumeric

Declare Hserial_Baud = 9600 ' Set baud rate to 9600
Declare HSerin_Pin = PORTC.7
Declare HSerout_Pin = PORTC.6

All_Digital = True
Clear
DelayMS 100

GoTo main

main:

Print At 1,1, "PRESS THE BUTTON"

If PORTB.7 = 0 Then GoTo lop1 ' when button pressed then PIC send data to PC

GoTo main

lop1:

HSerOut ["ABCDEF"]

GoTo lop2

lop2:

If PORTB.7 = 1 Then GoTo main ' when button released then goto main

GoTo lop2

End

John Lawton

Where have you set the device fuses?

top204

#2
The program is using the compiler's default fuses John, which are set up to use an external crystal and what should not be switched on, is switched off. :-) The default fuses are at the end of all .ppi files, and act as a safety net for users who have not mastered the dreadful mess of the Microchip Config Fuses yet. And I cannot blame them for that, because some of them even confuse me after all of these years. They have created a Frankenstein's Monster out of them, over the years, and some have very little use or meaning. But some university nerd thought they made sense, so the "ones at the top", who generally know very little about engineering, agree with them. :-)

Make sure you are using something between the microcontroller and the PC, so it inverts the signals. If using a serial port, use something like a MAX232 or a transistor to invert the data. If using USB, the USB to serial device will invert the signal for you.

Try the program listed below, because it works as expected in tests:
'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Transmit data from USART1 as a test, using an external 10MHz crystal attached to the microcontroller
' Written for the Positron8 compiler by Les Johnson
'
    Device = 18F46K22                       ' Tell the compiler what device is being compiled for
    Declare Xtal = 10                       ' Tell the compiler what speed the device will be operating at
'
' Setup USART1 for the HSer commands
'
    Declare Hserial_Baud = 9600             ' Tell the compiler what Baud rate to set for USART1
    Declare HRSOut_Pin = PORTC.6            ' Tell the compiler what pin to use for TX on USART1
    Declare HRSIn_Pin = PORTC.7             ' Tell the compiler what pin to use for RX on USART1

'-----------------------------------------------------------------------
' The main program starts here
'
Main:
    Do                                      ' Create a loop
        HSerOutLn ["HELLO WORLD"]           ' Transmit "HELLO WORLD" with a Carriage Return transmitted after it
        DelayMS 500                         ' Delay for half a second before transmitting again
    Loop                                    ' Do it forever

The program above will test your microcontroller to PC serial connections.

Make sure you are actually using a 10MHz crystal on the device.



John Lawton

#3
Quote from: top204 on Jul 12, 2022, 03:15 PMThe program is using the compiler's default fuses John, which are set up to use an external crystal and what should not be switched on, is switched off. :-) The default fuses are at the end of all .ppi files.

Ah, I can't remember when I didn't explicitly set the fuses, otherwise it's a bit like working in the dark :)

bjkrs

hİ, thanks for your support. I probably have a hardware problem. I will rewire.

bjkrs

Quote from: top204 on Jul 12, 2022, 03:15 PMThe program is using the compiler's default fuses John, which are set up to use an external crystal and what should not be switched on, is switched off. :-) The default fuses are at the end of all .ppi files.

Make sure you are using something between the microcontroller and the PC, so it inverts the signals. If using a serial port, use something like a MAX232 or a transistor to invert the data. If using USB, the USB to serial device will invert the signal for you.

Try the program listed below, because it works as expected in tests:
'
'  /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\    \/\\\                                                /\\\          /\\\
'  \/\\\\\\\\\\\/        /\\\\\    /\\\\\\\\\\    /\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'    \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\    \/\\\        \/\\\        /\\\\\\\\\\
'      \/\\\    \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\    \/\\\ /\\  /\\\/////\\\
'      \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\  \//\\\\\\\\/\\
'        \///        \///    \/////    \//////////    \//////////      \/////        \/////    \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Transmit data from USART1 as a test, using an external 10MHz crystal attached to the microcontroller
' Written for the Positron8 compiler by Les Johnson
'
    Device = 18F46K22                      ' Tell the compiler what device is being compiled for
    Declare Xtal = 10                      ' Tell the compiler what speed the device will be operating at
'
' Setup USART1 for the HSer commands
'
    Declare Hserial_Baud = 9600            ' Tell the compiler what Baud rate to set for USART1
    Declare HRSOut_Pin = PORTC.6            ' Tell the compiler what pin to use for TX on USART1
    Declare HRSIn_Pin = PORTC.7            ' Tell the compiler what pin to use for RX on USART1

'-----------------------------------------------------------------------
' The main program starts here
'
Main:
    Do                                      ' Create a loop
        HSerOutLn ["HELLO WORLD"]          ' Transmit "HELLO WORLD" with a Carriage Return transmitted after it
        DelayMS 500                        ' Delay for half a second before transmitting again
    Loop                                    ' Do it forever

The program above will test your microcontroller to PC serial connections.

Make sure you are actually using a 10MHz crystal on the device.




I will try it, thanks my friend

bjkrs

hi again,

Yes, my problem is hardware and I solved it, thanks to both of you for your support.