MCSPlus serial interface to EasyPIC6 not working?
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??
Answers to your questions and here are the configs
Quote:
Originally Posted by
mackrackit
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.
Quote:
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.
Code:
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
Tried your suggestons..no success
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?
Code:
' -----------------------[ 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
Tried both ways...I think 1st photo is correct.
Quote:
Originally Posted by
Bruce
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/e...anual_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?
EasyPic6 serial interface works w/ mBasic but not PBP??
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:
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??
Code:
'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
Change in approach to troubleshooting UART interface
Quote:
Originally Posted by
Darrel Taylor
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??
Code:
;--- 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
Here is the code for previous post
Here is the code for previous post
1 Attachment(s)
RX is connected to RX in my cable
Quote:
Originally Posted by
aratti
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!
Code:
'****************************************************************
;--- 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
Problem found...but don't know why?
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?