PDA

View Full Version : MCSPlus serial interface to EasyPIC6 not working?



jellis00
- 3rd March 2010, 21:53
Am not able to get serial communication from MCSPlus with EasyPic6 while running program on 18F4550.
I set the SW6 and SW7 for RC7 & RC6 respectively per the User Manal and MCU data sheet for the EUSART in the 18F4550. I also made sure the host computer had the COM1 serial interface set to 9600 BPS, 8 data bits, no parity and one stop bit (8N1) .
The MCU was programmed using MCSPlus as the editor, PICBASICpro as the compiler, and MPASM as the assembler to create a .hex file, which was then burned into the MCU using a USB interface from PICFLASH to the EasyPIC6.
After programming I have then been trying to use ICD that is built into MCSPlus to step the source code and monitor variable values, which requires the serial interface connection between the MCSPlus host and the EasyPIC where the program is running in the PIC18F4550. I keep getting a serial interface timeout when I start the ICD in MCSPlus even though I have made sure the seral interface is defined in the code and the PC's serial settings have been set to match the MCSPlus settings of COM1.
Can you please advise from above info what I am doing wrong that is causing the serial interface to timeout without connection??

mackrackit
- 3rd March 2010, 22:22
Does the easypic hava a level shifter (RS232) chip? If not you will need one using the PIC's USART.

And

with out seeing your configs and code we have no way of knowing if the chip is running at the speed you think it is.

jellis00
- 4th March 2010, 01:46
Does the easypic hava a level shifter (RS232) chip? If not you will need one using the PIC's USART.

Yes it has a MAX202 chip installed on the EASYPIC6 board.



with out seeing your configs and code we have no way of knowing if the chip is running at the speed you think it is.

Sorry about that...I see now I referenced my configs but forgot to include them. Here they are. One other relevant piceof info: the Easyic6 has a 8 MHz crystal installed for the MCU. I realize the DEFINE in the code must tell the compiler what the MCU clock is, and in this case I intend on this code using a USB interface, which is set by configs for the 48 MHz USB clock. Therefor the DEFINE to tell the MCU it is a 16 MHz MCU clock.
I have also tried both HYPERTERM and the USART Terminal that comes with mikroelectronica's EasyPic6 to see if the terminal makes a diference....they both never connect and timeout.
Would appreciate any advice you can give me.



ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

DEFINE OSC 16

mackrackit
- 4th March 2010, 02:53
Try defining the OSC at 48.
I am not near my data sheets , on a phone, so I am not sure if you have the PLL correct. But if you do have it PLLed to 48 then that is what you set the define as.

I use the same chip with a 4 external and run it at 48.

Bruce
- 4th March 2010, 20:13
DEFINE OSC 16 should work with your config settings. If you're trying to use the MCS+ ICD, make sure you compile with the ICD/Compile button. If you're just trying to verify the connection with HSEROUT, then use the normal Compile button.

jellis00
- 5th March 2010, 02:11
I tried both 48 and 16 MHz defines and also made sure the recompiles were with just the Compile button and not the Compile/ICD button.
I also generated a simpler program to test the serial inteerface that just reads the HSERIN from the PC host and then resends the same received character to the PC host with HSEROUT (see included code below). The PC host hyperterminal says the sends are going out, but never receive back any resends from the PIC. I also included in the HSERIN statement a timeout to a label that blinks LEDs as an error if timeout occurs. It does, so it confirms that the serial interface is not working and is timing out.
Almost seems like a hardware failure on the EasyPic6 side, but I don't want to RMA the EasyPic6 all the way back to Rumania to have them check/repair the unit due to the time delays and the cost....the EasyPic6 is my development board....just wish I could get the serial interface to it working so I could then use the MCSPlus ICD debugger with it.
At this point I am really baffled. Any other suggestions as to how I can verify the serial interface?



' -----------------------[ Program Description ]--------------------------
' Program is for a PIC18F2550/4550 & was tested in an EasyPic6 board.
' PICBASIC PRO program to send and receive from the hardware serial port
' LEDs count characters and flash error if none received for 10 seconds
'
' -------------[ Revision History ]--------------------------------------
' Version 1.0 Started on 03/04/2012

'--------------[ Define EEPROM usage ]-----------------------------------

' -----[ Device Declaration ]---------------------------------------------
;--- if you un-comment these, you must comment the ones in the .inc file--
ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

Include "Modedefs.Bas"
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
' User must make sure the AllDigital.pbp file
' is in same directory location as this source
' code before compiling.
'DEFINE SHOWDIGITAL 1 ' When uncommented will show analog settings
' in Assembler Results window

DEFINE OSC 16
DEFINE I2C_SLOW 1 ' Set i2c to the standard speed
DEFINE I2C_HOLD 1 ' Enable recieving i2c device to pause communication

'--------------[ Declare Variables, Aliases & Constants ]---------------
' Variables & Aliases for Pins
' ===============================================
char Var Byte ' Storage for serial character
cnt Var Byte ' Storage for character counter

' Constants
'==========

' Initialize Hardware
' ===================
'Set registers
TRISB = %11001111 ' Set PORTB.4,5 to outputs
PORTB = 0 ' Turn off LEDs
cnt = 0 ' Zero character counter

' Setup Hardware for uart
' =======================
'DEFINE HSER_BAUD 9600
'DEFINE HSER_RCSTA 90h
'DEFINE HSER_TXSTA 24h
'DEFINE HSER_CLROERR 1

' * NOTES for use with EasyPic6 development board:
' Set SW7.1 on for RC7 = RX and SW8.1 on for RC6 - TX
'For use with COG 2x16 LCD:
' - Turn on Port Expander switches SW6.1,SW6.2,SW6.3,SW6.4 & SW6.5.
' - Turn on COG LCD 2x16 switches SW10.1,SW10.2,SW10.3,SW10.4,SW10.5
' and SW10.6.

' Set EUSART configuration for serial interface to EasyPic6
' For MCSPlus ICD debugging only....comment out for operations
'TRISC.6 = 1
'TRISC.7 = 1
'RCSTA.7 = 1

'--------------------[ Begin Main Program Loop ]------------------------
mainloop:
PAUSE 100 ' Without this PAUSE, there's nothing to keep the Watch Dog
' Timer clear. LOW & GOTO don't generate CLRWDT instructions.
' See www.picbasic.co.uk/forum/showthread.php?p=84722#post84722
Hserin 10000, allon, [char] ' Get a char from serial port..if timeout go
' to label as error

Hserout [char] ' Send char out serial port

cnt = cnt + 1 ' Increment character count
PORTB = cnt << 4 ' Send count to LED

Goto mainloop ' Do it all over again

allon: PORTB = %00110000 ' Error - no character received
Pause 500 ' Blink all LEDs
PORTB = 0
Pause 500
Goto allon

End ' Safety measure to insure program stops if reaches here

mackrackit
- 5th March 2010, 02:55
Below are the setting for 9600 baud at 16MHz


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 25 ' 9600 Baud @ 0.16%

You have the ones in your code commented out.

Run this code and type numbers at the keyboard.


ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
DEFINE OSC 16

ADCON1 = 15 ' All I/O pins digital

X VAR BYTE
START:
RCSTA.4 = 0 : RCSTA.4 = 1
RCSTA=$90:TXSTA=$20:SPBRG=25
HSERIN [DEC X]
HSEROUT [DEC X,$d,$a]
GOTO START

Bruce
- 5th March 2010, 03:14
Set SW7.1 on for RC7 = RX and SW8.1 on for RC6 - TX
On SW7 & SW8 flip everything else to the OFF position leaving only switches #8 on each one ON. Does it work?

In: http://www.mikroe.com/pdf/easypic6/easypic6_manual_v100.pdf the photo in Figure 6-1 shows both DIP
switches for RC6 & RC7 on switch positions #1.

And just below this in Figure 6-2 they show RC6 & RC7 on DIP switch positions #8. Which is right?

jellis00
- 5th March 2010, 04:10
Below are the setting for 9600 baud at 16MHz


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 25 ' 9600 Baud @ 0.16%

You have the ones in your code commented out.

Run this code and type numbers at the keyboard.


ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
DEFINE OSC 16

ADCON1 = 15 ' All I/O pins digital
PORTB.6 = 0 ' Turn off the LEDs PORTB.7 = 0

X VAR BYTE
START:
RCSTA.4 = 0 : RCSTA.4 = 1
RCSTA=$90:TXSTA=$20:SPBRG=25
HSERIN [DEC X]
HSEROUT [DEC X,$d,$a]
GOTO START


Mackrackit, I created a .pbp file from your above code with a slight modification where I inserted a LED turn on just after the HSERIN and just after the HSEROUT statements. See the code below. Then when running the code and typing characters on the keyboard I do not see these respective lights come on in the EasyPic6. This says the HSERIN and the HSEROUT statements are never executing when the code is running and the PC terminal is connected. This implies a hardware failure somwhere in the EasyPic6 serial interface circuitry....do you agree???


ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
DEFINE OSC 16
TRISB = %00001111 ' Set PORTB.4,5,6,7 to outputs as test LEDs

ADCON1 = 15 ' All I/O pins digital
PORTB.6 = 0 ' Turn off the LEDs
PORTB.7 = 0

X VAR BYTE
START:
RCSTA.4 = 0 : RCSTA.4 = 1
RCSTA=$90:TXSTA=$20:SPBRG=25
HSERIN [DEC X]
PORTB.6 = 1 ' Turn on PortB.6 LED if this statement is executed
' as test of receiving a character
HSEROUT [DEC X,$d,$a]
PORTB.7 =1 ' Turn on PortB.7 LED if this statement is executed
' as test of HSEROUT having sent a character
GOTO START

jellis00
- 5th March 2010, 04:23
On SW7 & SW8 flip everything else to the OFF position leaving only switches #8 on each one ON. Does it work?

In: http://www.mikroe.com/pdf/easypic6/easypic6_manual_v100.pdf the photo in Figure 6-1 shows both DIP
switches for RC6 & RC7 on switch positions #1.

And just below this in Figure 6-2 they show RC6 & RC7 on DIP switch positions #8. Which is right?

Tried it both ways, Bruce, while running Mackrackit's code as I modified it above. And as I said in above post to him, no LED test lights turned on, indicating the HSERIN and HSEROUT statements never executed....meaning no receipt of the character I typed on the keboard by the HSERIN.

Any other ideas?

Bruce
- 5th March 2010, 04:39
I always include DEFINE HSER_CLROERR 1 if using HSERIN just to be sure it' never locked up on me, but I'm not sure that's the problem.

Try sending first. Something like HSEROUT ["Hello World",13,10] to MCS terminal. If this doesn't work, then try using SEROUT2 PORTC.6,84,["Hello World",13,10].

If you get nothing on screen, I would check my connection from RC6 to the PC side of the MAX IC, serial cable, etc.

If you have an O-Scope set it in a continuous HSEROUT loop while watching the MAX TX out pin to PC.

jellis00
- 5th March 2010, 04:50
I will try those ideas, Bruce.

Got to wondering if the MCU was actually running. I can see from the PRG light on the EasyPic6 it is getting programmed but in previous code didn't have any way to confirm it was actually running....if it weren't that could explain why the test LEDs didn't light in previous post and also possibly why the HSERIN and HSEROUT statement aren't executing...hence no communications.
I inserted a blinking LED in the loop in the below version and when I run it, it doesn't blink...indicating the MCU is not running!! Now I don't know what to do to make the MCU run.?????


ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L

ENDASM
Include "Modedefs.Bas"
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
' User must make sure the AllDigital.pbp file
' is in same directory location as this source
' code before compiling.

DEFINE OSC 16
TRISB = %00001111 ' Set PORTB.4,5,6,7 to outputs as test LEDs

ADCON1 = 15 ' All I/O pins digital
PORTB.5 = 0
PORTB.6 = 0 ' Turn off the LEDs
PORTB.7 = 0


X VAR BYTE

START:
PORTB.5 = 1 ' Blink LED as test that MCU is running
RCSTA.4 = 0 : RCSTA.4 = 1
RCSTA=$90:TXSTA=$20:SPBRG=25
HSERIN [DEC X]
PORTB.6 = 1 ' Turn on PortB.6 LED if this statement is executed
' as test of receiving a character
HSEROUT [DEC X,$d,$a]
PORTB.7 =1 ' Turn on PortB.7 LED if this statement is executed
' as test of HSEROUT having sent a character
PORTB.5 = 0
GOTO START

Bruce
- 5th March 2010, 04:56
I've never used this board, but it looks like there's a ton of jumpers on there. And if you're not getting even an LED to blink, I would bet you're just missing a jumper setting!

Might even try replacing the PIC.

Is the POWER LED ON?

jellis00
- 5th March 2010, 05:23
I've never used this board, but it looks like there's a ton of jumpers on there. And if you're not getting even an LED to blink, I would bet you're just missing a jumper setting!

Might even try replacing the PIC.
I just burned a test program into the chip via same programming path I've been using that is a "blinky LED". It works fine. This tells me that at least the MCU chip will run and is OK. However, from what I saw that I described in my previous post, the serial interface code is NOT running in the MCU. Don't know why it would run with one program and not the other???


Is the POWER LED ON?[/QUOTE] Yes it is.

I just was wondering if it might be the USB to Serial converter cable I have to use because the Laptop I am using doesn't have a true serial (RS232) interface connector. I am using an ATEN UC232A USB-to-serial converter cable that connects to the DB9 connector on the EasyPic6 serial interface. It has a light built in to the serial end of the cable that comes on when the TX and RX switch selections are correct on SW7 and SW9 and the MCU is powered up. I have heard before that some of these USB to serial cables don't always work with some serial interfaces. Have any ideas about this one?
If that isn't it, then it is looking more and more like a failure in one of the compnents in the EasyPic6 serial circuit.....possibly the MAX202 they use...just don't know how to text the circuit to see if it is a H/W failure.
I'm really running out of ideas.

mackrackit
- 5th March 2010, 12:15
You could test the board by removing the PIC and VERY VERY carefully plug a jumper wire in across the PIC TX/RX pin sockets. That will give a loop back to the PC when something is sent.

And/or

Program the chip, put it ina breadboard then connect to the PC. If you have the hardware.
Use SEROUT2 with an inverted MODE then an inverter chip is not needed. Send "hello wold" like Bruce mentioned.

Jump pins 2 and 3 at the USB/serial converter and do a loop back test.

With out an "O" scope, write a code to send something in a loop, something long. with a second pause between sends. Connect a DVM to zero and serial pin #2 of the EasyPic and see it the is any activity from the on-board inverter chip. If the DVM fluctuates then the inverter chip is probably working.

jellis00
- 6th March 2010, 02:15
You could test the board by removing the PIC and VERY VERY carefully plug a jumper wire in across the PIC TX/RX pin sockets. That will give a loop back to the PC when something is sent.
Tried this and got no loop back to the PC terminal display. Also put an O-scope on the jumper and see no activity when typing characters on the PC keyboard. That tells me no transmissions are reaching the RX pin on the MCU on the EasyPic6...possibly MAX202 or USB-to-serial cable bad?



Jump pins 2 and 3 at the USB/serial converter and do a loop back test.
[\QUOTE]
Did this and type characters at the PC keyboard and no loop back characters on the RX side of the terminal. Also connected an O-scope to Pin-2 of the Male DB9 connector (TX from PC) and no activity when typing characters on PC keyboard. This test tells me that the UC232A cable (USB-to-serial) is probably not wired correctly for USB to serial conversion. It still doesn't eliminate the MAX202 as the problem.

[QUOTE].....Connect a DVM to zero and serial pin #2 of the EasyPic and see it the is any activity from the on-board inverter chip. If the DVM fluctuates then the inverter chip is probably working.
By this do you mean connect the DVM to check for voltage at the MCU's RX pin socket location on the EasyPic6 with the MCU removed? I don't undersand which serial pin #2 you are referring to. It seems to me that connecting to the RX socket location would also confirm whether the inverter chip is working as long as I know the cable is good. Would appreciate your clarification on that.

mackrackit
- 6th March 2010, 03:08
By this do you mean connect the DVM to check for voltage at the MCU's RX pin socket location on the EasyPic6 with the MCU removed? I don't undersand which serial pin #2 you are referring to. It seems to me that connecting to the RX socket location would also confirm whether the inverter chip is working as long as I know the cable is good. Would appreciate your clarification on that.
Serial pin#2 would be the RX from the test board. I did not know that you have an O scope.
Write a code to send serial data and connect your scope to the EasyPic board. That will tell you if anything is getting out.

jellis00
- 10th March 2010, 00:16
Have made some progress in isolating the problem. Finally found a laptop with true serial interface so I could avoid use of USB-to-serial adapter cable. To confirm EasyPic6 interface was working I programmed a PIC16F877 chip with the standard loopback test mikroBasic code that came as sample with the EasyPic6. With this code the serial interface worked fine. This confirms there is nothing wrong with the serial interface hardware in the EasyPic6. For reference here is that simple code:


' *
' * Project name:
' UART (Simple usage of UART module library functions)
' * Copyright:
' (c) Mikroelektronika, 2009.
' * Revision History:
' 20080930:
' - initial release;
' - 20090720 - modified by Slavisa Zlatanovic;
' * Description:
' This code demonstrates how to use uart library routines. Upon receiving
' data via RS232, MCU immediately sends it back to the sender.
' * Test configuration:
' MCU: PIC16F887
' http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf
' Dev.Board: EasyPIC6
' http://www.mikroe.com/en/tools/easypic6/
' Oscillator: HS, 08.0000 MHz
' Ext. Modules: -
' SW: mikroBasic PRO for PIC
' http://www.mikroe.com/en/compilers/mikrobasic/pro/pic/
' * NOTES:
' - RX and TX UART switches on EasyPIC6 should be turned ON (SW7.1 and SW8.1).
' *

program UART
dim uart_rd as byte

main:
UART1_Init(9600) ' Initialize UART module at 9600 bps
Delay_ms(100) ' Wait for UART module to stabilize

UART1_Write_Text("Ready")
UART1_Write(10) ' Line Feed
UART1_Write(13) ' Carriage Return

while (TRUE) ' Endless loop
if (UART1_Data_Ready() <> 0) then ' If data is received,
uart_rd = UART1_Read() ' read the received data,
UART1_Write(uart_rd) ' and send data via UART
end if
wend
end.

Then I programmed my 18F4550 with the below PBP code that is an adaptation I got from Mackrackit. Although the code compiles and runs, the serial interface doesn't work....no character loopbacks to Hyperterminal when typed and an oscilloscope connection to the RX pin of the 18F4550 shows nothing when characters are typed into Hyperterminal.

I have studied the code in both cases and see little functional difference. Yet one works and the other doesn't.
Can anyone advise me what changes to make to the PBP code to get it to work??


'ASM ; 18F2550/4550, 8mhz crystal
' __CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
' __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
' __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
' __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
' __CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
' __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L

'ENDASM
Include "Modedefs.Bas"

DEFINE OSC 16

'Register Settings
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 160 ' 9600 Baud @ 16MHz, -0.08%
SPBRGH = 1
' BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

TRISB = %00000000 ' Set PORTB to outputs as test LEDs
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
' User must make sure the AllDigital.pbp file
' is in same directory location as this source
' code before compiling.
PORTB = 0 ' Turn off the LEDs
HIGH PORTB.4 ' Blink the one Test LED as proof MCU is running
PAUSE 500
LOW PORTB.4

' Declare variables
X VAR BYTE

START:
RCSTA.4 = 0 : RCSTA.4 = 1
HSERIN [DEC X]
PORTB.5 = 1 ' Turn on PortB.6 LED if this statement is executed
' as test of receiving a character
HSEROUT [DEC X,$d,$a]
PORTB.6 =1 ' Turn on PortB.7 LED if this statement is executed
' as test of HSEROUT having sent a character
GOTO START

Darrel Taylor
- 10th March 2010, 02:29
Hint:

There are 2 buttons available in mister-e's program ...

http://www.pbpgroup.com/files/mre_butt.JPG

mackrackit
- 10th March 2010, 02:47
Post #7 ??

Darrel Taylor
- 10th March 2010, 03:00
Exactly, post #7 is a good example of the same problem.

Setting registers, instead of DEFINEs for HSERIN/OUT. :p
<br>

mackrackit
- 10th March 2010, 03:36
Post #7 should have the correct settings.

What is wrong with setting registers? I do this at times when I need to change the baud rate on the fly.

Darrel Taylor
- 10th March 2010, 03:36
Hmmm, suddenly I was in a world where everything was reversed.

Such as using defines when reading RCREG.
Turned into setting regs when using HSERIN.

Strange ... very strange ...
OOPS

jellis00
- 11th March 2010, 00:14
Hint:

There are 2 buttons available in mister-e's program ...

http://www.pbpgroup.com/files/mre_butt.JPG

OK, I judge by the exchanges between DT and Mackrackit that I should have used the DEFINES button with Mister_e's PICMultiCalc. So I did. However, as a change in approach to my troubleshooting to isolate this UART problem with my PBP code, I have taken the following approach:
1) Since I know that my EasyPic6 UART interface works with the sample loopback routine that came with it that is written in microelekBasic (see earlier post) for a 16F887 chip, I have discarded my 18F4550 chip for now to see if I can get PBPro code that is functionally identical to the microBasic routine to also work with the 16F887 chip in the EasyPic6.
2) I have insured the _configs for my code result in the identical config bits that are generated by the microBasic code with the EasyPic6.
3) Please see this PBPro code below and note the configs that appear to be equivalent to the microBasic version and also how I used PICMultiCalc to define the UART setup and then studied the data sheet for the 16F877 to make sure it was correct, as shown by my extensive commenting of the UART setup.
4) I then programmed the 16F887 chip using MCSPlus, PBPro 2.6 compiler, MPASM assembler, and the PICFLASH interface to actually download the .hex file to the chip. PICFLASH also permits me to double check the configs before burning the chip.
5) After the chip is running, I then tried HYPERTERM to type some characters over the interface. Nothing indicated on HYPERTERM in the received loopback, although this same process worked with the microBasic routine.
6) Also tried the comm interface in MCSPlus to communicate with the running code and although it showed that the typed characters were accumulating in the TX tally at the bottom of the screen, no characters were being tallied in the RX entry. SAME PROBLEM AS OBSERVED WITH 18F4550!!:mad:
7) In all of the above cases I assured that both the PC and the PIC ends of the EUART interface were set to COM1/9600/8bits/no parity/1 stop bit.

The continuing failure of the PBPro code, that is as close to identical to the microBasic code as I can make it, is very frustrating to me!
Can anyone see what is wrong with this PBPro code to cause it to continue to fail in this loopback test between a PC terminal and the running PIC??


;--- if you un-comment these, you must comment the ones in the .inc file--
ASM ; 16F887, 8mhz crystal
__CONFIG _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _IESO_ON & _FCMEN_ON & _LVP_OFF & _CP_OFF & _BOR_OFF
ENDASM
Include "Modedefs.Bas"

DEFINE OSC 8
'Register Settings
TRISB = %00000000 ' Set PORTB to outputs as test LEDs
TRISC.6 = 1 ' EUSART control will automatically reconfigure
TRISC.7 = 1 ' these pins from input to output as needed.

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
' RCSTA.7 = SPEN = 1 for Serial port enabled (configures
' RX/DT & TX/CK pins as serial port pins).
' RCSTA.4 = CREN = 1 for Asynchronous Continuous Receive
' Therefore RCSTA = %10010000 = 90h
DEFINE HSER_TXSTA 20h ' Enable transmit, 8-bit, Asynchronous mode
' TXSTA.5 = TXEN = 1 for Transmit enabled
' TXSTA.4 = SYNC = 0 for Asynchronous mode
' TXSTA.2 = BRGH = 0 for High Speed Asynchronous Baud Rate
' Therefore TXSTA = %00100000 = 20h
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 51 ' 9600 Baud @ 8MHz, 0.16%, , 51 = 33h = %00110011
SPBRGH = 0
BAUDCTL.3 = 1 ' Enable 16 bit baudrate generator

INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
' User must make sure the AllDigital.pbp file
' is in same directory location as this source
' code before compiling.
PORTB = 0 ' Turn off the LEDs
HIGH PORTB.4 ' Blink the one Test LED as proof MCU is running
PAUSE 500 ' at tiime of power up.
LOW PORTB.4

' Declare variables
X VAR BYTE ' Variable holds received character from UART

START:
HSERIN [DEC X]
PORTB.5 = 1 ' Turn on PortB.6 LED if this statement is executed
' as a test of receiving a character.
HSEROUT [DEC X,$d,$a]
PORTB.6 =1 ' Turn on PortB.7 LED if this statement is executed
' as a test of HSEROUT having sent a character.
GOTO START

mackrackit
- 11th March 2010, 00:28
Hang in there. We will get it working.

But

Where's the code?

jellis00
- 11th March 2010, 00:31
Here is the code for previous post

Ioannis
- 11th March 2010, 08:24
Hmmm, suddenly I was in a world where everything was reversed.

Such as using defines when reading RCREG.
Turned into setting regs when using HSERIN.

Strange ... very strange ...
OOPS

I'd like one of those too, please :)

Ioannis

mackrackit
- 11th March 2010, 09:47
I have pins
RC7 connected to MAX232 pin 12
RC6 connected to MAX232 pin 11

MAX232 pin 13 connected to DB9 pin3
MAX232 pin 14 connected to DB9 pin2

Both of the codes below do the same thing. I do not have an EasyPic board but this has been tested on breadboard.


'16F887 HERSIN/OUT
@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
OSCCON = %01110000
DEFINE OSC 8
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 51 ' 9600 Baud @ SPBRGH = 0 25 FOR 4MHz
BAUDCTL.3 = 1 ' Enable 16 bit baudrate generator
X VAR BYTE
RUN:
HSERIN [X]
HSEROUT [X,$d,$a]
GOTO RUN


'16F887 HERSIN/OUT #2
@ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
OSCCON = %01110000
BAUDCTL.3 = 1
X VAR BYTE
RUN:
RCSTA=$90:TXSTA=$20:SPBRG=51
HSERIN [X]
RCSTA.4 = 0 : RCSTA.4 = 1
HSEROUT [X,$d,$a]
GOTO RUN

aratti
- 11th March 2010, 14:09
Did you check the cable connecting the two units? There is the possibility that you have Rx connected to Rx. See the attached picture.

Al.

jellis00
- 18th March 2010, 23:06
Did you check the cable connecting the two units? There is the possibility that you have Rx connected to Rx. See the attached picture.

Al.
I used a multimeter to check the connectivity on each pin of the DB9 connectors from the male end to the female end of my cable. My cable is wired as a straight through connection...in other words:

Male Pin Female Pin
2-RX 2-Connected (as RX?)
3-TX 3-Connected (as TX?)
5-GND 4-Connected as Gnd
7-RTS 7-Connected as RTS
8-CTS 8-Connected as CTS

This appears to be the case you warn about where RX is connected to RX. Yet this cable works OK as a serial interface with the EasyPic6 when running their sample microBasic coded loopback example when using Hyperterminal or other terminal emulators. However, when I connect it to the EasyPic6 and try to run any of the PicBasicPro codes listed in the above posts, the HSERIN statement does NOT receive a character and hence no loopbacks.

I checked the schematic for the EasyPic6 and the female DB9 connector is wired to the MAX202 chip as shown in the attached schematic (Pin2 to T1 OUT and Pin3 to R1 IN). That means that from the PC end of the cable RX is wired to T1 OUT and TX is wired to R1 IN, which I would interpret to be a correct interface. However it doesn't work with the PicBasicPro HSERIN statement.

Does all this mean that my cable straight through connections will work with mikroBasic and the EasyPic6 interface, but will not work with the HSERIN statement in PicBasicPro and the EasyPic6 interface??

Here is my current code. It executes OK down to the HSERIN statement as evidenced by the clearing of the LCD in the statement just before the HSERIN. But it confirms that the HSERIN statement is not executing because the LCDOUT statement just after the HSERIN is never executing when characters are typed at the terminal emulator, and the heartbeat LED in the mainloop is never blinking.
Can anyone tell me why this HSERIN statement is not executing with this interface? I am very frustrated at this point!


'************************************************* ***************
;--- if you un-comment these, you must comment the ones in the .inc file--
ASM ; 16F887, 8mhz crystal
__CONFIG _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _IESO_ON & _FCMEN_ON & _LVP_OFF & _BOR_OFF
ENDASM
OSCCON = %01110000
Include "Modedefs.Bas"
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
' User must make sure the AllDigital.pbp file
' is in same directory location as this source
' code before compiling.
'DEFINE SHOWDIGITAL 1 ' When uncommented will show analog settings
' in Assembler Results window.
' A/D & Comparators disabled for digital ops
' All of these statements should be commented out when using the
' INCLUDE "AllDigital.pbp" statement to set digital ops.
'ADCON1 = %00001111
'CMCON = 7

DEFINE OSC 8
'Register Settings
TRISA = 0 ' PortA connections are used for LCD interface
TRISB = %00000000 ' Set PORTB to outputs as test LEDs
TRISC.0 = 0 ' PortC.0 is used for a Heartbeat LED
TRISC.2 = 0 ' PortC.2 is used for the LCD R/W connection
TRISC.6 = 1 ' EUSART control will automatically reconfigure
TRISC.7 = 1 ' these pins from input to output as needed.

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
' RCSTA.7 = SPEN = 1 for Serial port enabled (configures
' RX/DT & TX/CK pins as serial port pins).
' RCSTA.4 = CREN = 1 for Asynchronous Continuous Receive
' Therefore RCSTA = %10010000 = 90h
DEFINE HSER_TXSTA 20h ' Enable transmit, 8-bit, Asynchronous mode
' TXSTA.5 = TXEN = 1 for Transmit enabled
' TXSTA.4 = SYNC = 0 for Asynchronous mode
' TXSTA.2 = BRGH = 0 for High Speed Asynchronous Baud Rate
' Therefore TXSTA = %00100000 = 20h
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 51 ' 9600 Baud @ 8MHz, 0.16%, , 51 = 33h = %00110011
SPBRGH = 0
BAUDCTL.3 = 1 ' Enable 16 bit baudrate generator

' Make sure that SW6.8 on the EasyPic6 is set to ON position before powerup.
' Make sure that SW7.1 & SW8.1 on EasyPic6 are set to ON before powerup.
' Initialize the display

Pause 500 ' Wait for LCD to startup after power on
GOSUB InitializeDisplay

PORTB = 0 ' Turn off the LEDs
HIGH PORTB.4 ' Blink the one Test LED as proof MCU is running
PAUSE 500 ' at time of power up.
LOW PORTB.4

' Declare variables
X VAR BYTE ' Variable holds received character from UART

mainloop:
PORTB.5 = 1 ' Turn on PortB.5 LED if this statement is executed
' as a test of entering START loop
Lcdout $fe, 1 ' Clear LCD screen
PORTC.0 = 1 ' Blink Heartbeat LED during mainloop
HSERIN [DEC X]
Lcdout $fe,1,"RCVD" ' Display RCVD on 1st line
Pause 500 ' Wait .5 second
PORTC.0 = 0
HSEROUT [DEC X,$d,$a]
PORTB.6 =1 ' Turn on PortB.6 LED if this statement is executed
' as a test of HSEROUT having sent a character.
LCDOUT $fe,$C0,"TXMTD" ' Jump to 2ne line & show TXMTD
Pause 500
Lcdout $fe, 1 ' Clear LCD screen
GOTO mainloop

' ----------------------[ START LIST OF SUBROUTINES ]-------------------
'************************************************* **********************

InitializeDisplay: ' Commented out till LCD installed
'=================
'--SETUP FOR USING 2x16 LCD THAT IS INSTALLED IN EASYPIC6-----
' LCD DEFINES FOR USING 2x16 LCD with PortA in EASYPIC6
'================================================= =====
DEFINE LCD_DREG PORTA ' Use PORTA for LCD Data
DEFINE LCD_DBIT 0 ' Use lower(4) 4 bits of PORTA
' PORTA.0 thru PORTA.3 connects to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTA ' PORTA for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 4 ' PORTA.4 pin for LCD's RS line
DEFINE LCD_RWREG PORTC ' LCD read/write port
DEFINE LCD_RWBIT 2 ' LCD read/write bit
DEFINE LCD_EREG PORTA ' PORTA for Enable (E) bit
DEFINE LCD_EBIT 5 ' PORTA.5 pin for LCD's E line
DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 1500 ' Command Delay (uS)
DEFINE LCD_DATAUS 44 ' Data Delay (uS)

' DEFINE LCD Control Constants
K CON $FE ' Control Byte ($FE)
Clr CON $01 ' Clear the display
Line1 CON 128 ' Point to beginning of line 1 ($80)
Line2 CON 192 ' Point to beginning of line 2 ($C0)

' Test the LCD during initialization
LCDOut K,CLR:Pause 50 ' Clear Display
LCDOut K,Line1+3," LCD TEST " ' Display "RTC TEST" on 1st line
Pause 500
LCDOut K,Line2+2,"..Power On.. !!" ' Display "Power on" on 2nd line
PAUSE 1000
Return

mackrackit
- 18th March 2010, 23:35
Yes , you need a cable that goes from
2 to 3
and
3 to 2
and
5 to 5

Go down to radio shack and get a couple of connectors. Roll you own.

jellis00
- 19th March 2010, 00:03
By comparing Mackrakit's two codes in his above post to what I was trying to do, I noticed that he used the statement "HSERIN [X]" whereas I had been using "HSERIN [DEC X]". When I changed this statement in my code to match his the serial interface works! But I don't know why? I see in the PBP manual that DEC is a legitimate modifier for the HSERIN statement. How come it doesn't work in my code?

jellis00
- 19th March 2010, 00:07
Yes , you need a cable that goes from
2 to 3
and
3 to 2
and
5 to 5

Go down to radio shack and get a couple of connectors. Roll you own.
In fact, as I tried to describe in my above post, the way the MAX202 is wired in the EasyPic6 to the Female DB9 connector it does crossover the 2 to 3 and 3 to 2 pins from the cable so that the signals are correct when they get to the MCU. See the schematic I posted above.

Thanks so much for all your help with this. I would appreciate an explanation of my question regarding HSERIN [X] versus HSERIN [DEC X].

mackrackit
- 19th March 2010, 03:02
I did not get the cross over part of your other post...

The DEC thing
If like this


'Only numbers will work
HSERIN [DEC X]
HSEROUT [DEC X,$d,$a]



'Letters and numbers
HSERIN [X]
HSEROUT [X,$d,$a]



'Only receive numbers and output ASC||
'66 will return B
HSERIN [DEC X]
HSEROUT [X,$d,$a]



'Will receive letters and numbers and output decimal
'B returns 66 and 13 -- carriage return
HSERIN [X]
HSEROUT [DEC X,$d,$a]