Serout/Serout2 and PIC18F97J60 (100 pin)
Hi gurus,
anyone knows WHY this piece of code DOES NOT WORK ???!!!???
Basically it should send serially the control byte for a MeLabs LCD display
Instead, I got just junk and instead of receiving 5 character I receice sometimes 2, some other times 3.... But anytime NOT the correct characters.
I've used all the hardware USART, so I can't use no others and I cannot even modify the board to have a different "multiplexing" solution for the hardware serial port...
I'm using a resonator at 25Mhz
Code:
DEFINE OSC 25 'Set the Crystal Clock speed
INCLUDE "modedefs.bas" 'Inline compiler's pre-defined constants
ADCON0 = 0 'AD converter module 0 = disabled
ADCON1 = %00001111 'Set all analog pins to digital
ADCON2 = %00000000
CMCON = %00000111 'Comparator = disabled
INTCON = %00111000
INTCON2 = %10000000
INTCON3 = %00000000
RCON.7 = %00000000
EECON2.5 = 0 'Ethernet Module Disabled
SSP1CON1.5 = 0 'Disable SPI 1 and set pins as GPIO
SSP2CON1.5 = 0 'Disable SPI 2 and set pins as GPIO
TRISD.7 = 0 'PortD7 = RS-232 TX output for Display
LCD var PORTD.7
Main:
SEROUT2 LCD, N9600, [$1B, $30, $1B, $2A, $FF] 'Clear the display and set full-on backlight
pause 1000
GOTO Main
My settings for programming the Pic are the following:
Watchdog timer: Enabled
Stack Overflow Reset enable: Enabled
Extended Cpu Enable: Disabled
Code protect 000000 - 01FFFF: Disabled
Oscillator: OSC1/OSC2 as primary, HS Osc
Fail Safe Monitor Clock Enable: Enabled
Internal External Switch Over Enable: Enabled
Watchdog Timer Postscale: 1:512
External Address Bus Shift enable: Enabled
External Memory Bus Address Mode: Microcontroller mode, External bus disabled
Data Bus Width Select: 16-bit
External Bus Wait enabled: Ignore MEMCON.WAIT, Device Will not Wait
CCP2 Mux: ECCP2 I/O MUXED with RC1
ECCP Mux: P1B/P1C On RE6/RE5, P3B/P3C On RE4/RE3
Ethernet Led Enable: LedA/LedB On RA0/RA1 with Ethernet, RA0/AN0 without
I don't know what else to thing about. Any change to have Serout (and even Serout2 and Serin at work) simply does not work.
Could be something weird with the Configuration's Bits settings?
Thank to all in advance.
There is something wrong in PBP
Ok guys,
it definitively seems that there is something wrong in the PBP library somewhere.
The Serout (and Serout2), with PBP2.50A, and the program below, it JUST send 2 or 3 random character (yes, sometimes 2, some other times 3...)
I've putted a line in the code to flash a led to prove that the loop is going, but putting a scope on the output (on the pin PortD.7), I see only the transmission JUST after the reset and then NOTHING ELSE even if the loop is going and the led is flashing. So the instruction Serout2 bla bla bla, it is simply IGNORED! No transmissions at all, neighter the weird one. Just some character after the power-on.
The chip is again the PIC18F97J60 (100 pins version).
Any idea?
Code:
DEFINE OSC 25 'Set the Crystal Clock speed
INCLUDE "modedefs.bas" 'Inline compiler's pre-defined constants
ADCON0 = 0 'AD converter module 0 = disabled
ADCON1 = %00001111 'Set all analog pins to digital
ADCON2 = %00000000
CMCON = %00000111 'Comparator = disabled
INTCON = %00111000
INTCON2 = %10000000
INTCON3 = %00000000
RCON.7 = %00000000
EECON2.5 = 0 'Ethernet Module Disabled
SSP1CON1.5 = 0 'Disable SPI 1 and set pins as GPIO
SSP2CON1.5 = 0 'Disable SPI 2 and set pins as GPIO
TRISJ.7 = 0
TRISD.7 = 0 'PortD7 = RS-232 TX output for Display
LCD var PORTD.7
LED_what var PORTJ.7
Main:
SEROUT2 LCD, N9600, ["Hello World",13,10]
pause 1000
LED_what = ~ LED_what
GOTO Main
Thank you.
Something is working now...
Thank you Skimask,
is exactly what I did last night.
Conclusion:
The chip is FRIED!
There is something wrong with the PortD and PortC.
Actually a new board with another chip it work properly!
My apologises...
I've also apologized with MeLabs... even if I submitted another issue to them.
The new (old) one is related to the fact that the PIR1.5 register seems never find a character in the buffer even if I know that is sure there.
DEFINE HSER_CLROERR 1 and DEFINE HSER2_CLROERR 1 are both at the top of the program.
Things start going bad if I use some I2C command and then inquiry the PIR1.5
What I do not understand is that inquiring PIR3.5 (for the other attached device), it work regularly at any speed (between 2400 and 115200)
the only way to get data from the device attached is to use HSerin with a timeout of 10ms...
If I DON'T USE any I2C commands, both PIR1.5 and PIR3.5 reflect the correct data and behaviour...
I've already posted this strange things in a more detailed post:
http://www.picbasic.co.uk/forum/showthread.php?t=8638
Thank you all guys.
Hope in some hint...