18F46K22 USART

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

18F46K22 USART

Post by Coccoliso » Thu Feb 20, 2014 11:39 pm

There is no way to communicate from MPU to PC for a setup problem in USART.BAS.
Can anyone tell me how to manually set the module OPTION in order to communicate at any speed with the 18F46K22?
There are tools that allow you to calculate the parameters BRGH and SPBRG but as "digests them" the module USART.BAS ? .
I set the internal oscillator to 16MHz and I put it in a module include Config but nothing.
The strange thing is that the number of characters transferred seems to be correct .. I have to invert the signals DB9 or connect directly to the MPU?
I'm stumped! :shock:

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: 18F46K22 USART

Post by Jerry Messina » Fri Feb 21, 2014 2:11 pm

I have to invert the signals DB9 or connect directly to the MPU?

My first question is are you using an RS232 interface chip like a MAX232 to handle the proper voltage levels?
If so, that chip does all the required inversions you need.

You can't connect RS232 from a DB9 directly to the PIC.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: 18F46K22 USART

Post by Coccoliso » Fri Feb 21, 2014 5:24 pm

Hello,

MPU at 3,3V convertion of TX/RX made with discrete component .. the truth is that I need to check the status of the module ENC28J60 ETHERNET with that UART.
I tried the UART part individually and now with XT mode with a crystal oscillator running at 12MHz, all works fine.
The problem comes when I use the source of any of the examples of the conversion from the stack TCPIP done by David John Barker.
I use a module that mounts the ENC28J60, quartz and RJ connected to the SP1 of a 18F46K22 and the CS at RC2 pin.
It seems that everything halt at initialize point in one included module.. and then I took a look at the management of the EEPROM ..
I was convinced that we could use the EEPROM of the MPU but now I'm not convinced since I have seen the wiring diagrams of the modules used at the time .
A new dilemma for tomorrow !

Any IDEA for the halt in initialization ? Ethernet module blink but nothing else !

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: 18F46K22 USART

Post by Jerry Messina » Fri Feb 21, 2014 7:40 pm

Any IDEA for the halt in initialization ? Ethernet module blink but nothing else !
There are a number of places where things can get held up, but usually the issue is not getting the SPI port setup properly to communicate with the ENC, and things get stuck in MACInit().

In addition to the SPI1 CLK, SDI, and SDO pins you need to have two additional connections defined, a CS and a RST pin:

Code: Select all

// important configurations...
#option ENC28J60_CS = PORTD.6		// << SET THIS TO MATCH YOUR BOARD
#option ENC28J60_RST = PORTC.0		// << AND THIS

#option NET_ICMP = true   // enable ping 
#option NET_DHCP = true   // enable Dynamic Host Configuration Protocol (DHCP)
Include "NETApp.bas"      // always first!
Also, make sure you have turned off the analog functions for any pins you are using.

By default, the ENC LEDs will blink to indicate LINK and RX activity even if there's no communication with the PIC.
At least you know the ENC is running...

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: 18F46K22 USART

Post by Coccoliso » Sat Feb 22, 2014 9:38 am

Hello , GOOD NEWS! :lol:

There were several hardware problems and one software problems:
HW:
1) the levels of 3.3V RS232/TTL converter has problems of conversion and :oops: now I go to the usual circuit with a module with MAXIM IC ( 3.3V version )
2) The pull-up resistor RST line was too high (100K) and now, with a 10K resistor, ENC module reset correctly :wink:
SW:
1) DAMNED .. 46K22 :x addition to having to set "immediately" after resetting the internal oscillator I also had to call the SetAllDigital () at the same point .. for those who can serve:


MAIN PROGRAM MODULE (valid for every SF ETHERNET SAMPLE) :

Device = 18F46K22
Clock = 16


// important configurations...
#option ENC28J60_CS = PORTC.2
#option ENC28J60_RS = PORTD.3
#option NET_ICMP = true // enable ping
#option NET_DHCP = true // enable Dynamic Host Configuration Protocol (DHCP)
Include "intosc.bas" // <-----------------
Include "NETApp.bas" // always first!
....
....

EXTERNAL SETUP FILE (IntOSC.BAS) :

Module IntOSC
Config
FOSC = INTIO67,
PLLCFG = off,
PWRTEN = On,
WDTEN = off,
MCLRE = INTMCLR,
LVP = OFF,
CP0 = OFF,
PBADEN = OFF,
STVREN = off 'on

Include "SetDigitalIO.bas"
SetAllDigital() // Standard ADC switch off command

OSCCON = %01110000 // 16MHz internal oscillator
OSCTUNE = %00000000

Post Reply