
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
Bookmarks