PDA

View Full Version : Serout/Serout2 and PIC18F97J60 (100 pin)



mikebar
- 18th May 2008, 09:29
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



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.

mikebar
- 18th May 2008, 13:45
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?




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.

mikendee
- 18th May 2008, 14:47
From one Mike to another,
I'm not sure on this, but I think that you can only use modedefs.bas and N9600 mode with the SEROUT command not with SEROUT2.

skimask
- 18th May 2008, 20:16
SEROUT2 LCD, 84, ["Hello World",13,10]

mikebar
- 19th May 2008, 02:39
Thank you Skimask and Mikendee.
I've already tested the code putting 84 instead of N9600, but nothing.
Actually I modified the program in order to increase a BYTE sized variable "instead" of the 84.
So, pressig one button, I get that variable increased by 1 (and toggle a led).
Pressing another button I get that variable decreased by 1 (and toggle the same above led).

The loop is working because I see the toggling of the LED each time I press some button (debounced as well), but still nothing good...


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
serSpeed var byte

serspeed = 84
TestLoop:
serout2 PortD.7, SERSPEED, ["SerSpeed=", dec serSpeed,13,10]
if SW_ManualReset = 0 then
pause 10
if sw_manualreset = 0 then
LED_what = ~ LED_what
serspeed = serspeed - 1
endif
while sw_manualreset = 0
wend
LED_what = ~ LED_what
endif
if SW_PWR_On_Off = 0 then
pause 10
if SW_PWR_On_Off = 0 then
LED_what = ~ LED_what
serspeed = serspeed + 1
endif
while sw_pwr_on_off = 0
wend
LED_what = ~ LED_what
endif
pause 500
goto TestLoop

After the first weird sending then the PortD.7 pin is just muted.
No other sending even if the loop is still going. Actually if I press one of the buttons, I see that the led is toggling.

Same result if I change on any pin on PortC.
Of course, neighter Serin/Serin2 work...

I submitted the issue to Melabs too.

Any idea in the meanwhile?

skimask
- 19th May 2008, 14:05
Time to break it down...
Does the old blinky LED program blink at the proper rate?

led var portd.7 : output led
main: led = 1 : pause 500 : led = 0 : pause 500 : goto main
1 second blinks?

mister_e
- 19th May 2008, 16:17
..........never mind......................

mikebar
- 20th May 2008, 03:42
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...

mister_e
- 20th May 2008, 03:48
That's weird... i'll order few sample of this chip just for fun...

mikebar
- 20th May 2008, 04:06
Mister-e,
thank you very much for your curiosity.
Be prepared. The package IS EXTREMELY SMALL!

Let me know if you discover sothing.

Thank you again.

mister_e
- 20th May 2008, 04:16
No problem, it's an interesting PIC anyways. I'm impressed the 40$ PICKIT 2 support it... while some much more expensive programmer i have don't :eek: