MCSPlus serial interface to EasyPIC6 not working?


Closed Thread
Results 1 to 34 of 34

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Exactly, post #7 is a good example of the same problem.

    Setting registers, instead of DEFINEs for HSERIN/OUT.

    DT

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    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
    DT

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170

    Default

    Quote Originally Posted by Darrel Taylor View Post
    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
    Last edited by Ioannis; - 11th March 2010 at 08:26.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    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.
    Code:
    '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
    Code:
    '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
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    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.
    Attached Images Attached Images  
    All progress began with an idea

  7. #7
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default RX is connected to RX in my cable

    Quote Originally Posted by aratti View Post
    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
    Attached Images Attached Images  
    Last edited by jellis00; - 18th March 2010 at 23:27.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Wink 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?

Similar Threads

  1. Please help with EDE702 - Serial to LCD interface
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th October 2008, 02:48
  2. 32-bit Quadrature Counter With Serial Interface
    By precision in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th June 2008, 02:49
  3. Serial interface with RFID reader
    By brid0030 in forum Serial
    Replies: 8
    Last Post: - 23rd January 2007, 06:23
  4. Replies: 0
    Last Post: - 25th November 2005, 14:35
  5. PIC16F877 to RFID Module Serial Interface
    By koossa in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th May 2005, 06:03

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts