PIC to PIC TX RX and PIC to PC COM RX ..a little help please


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 68
  1. #1

    Default PIC to PIC TX RX and PIC to PC COM RX ..a little help please

    Hi all
    (sorry about the long post!)

    Thanks to all those who have helped me and lots of late nights reading and 'PIC'-ing, I have finally reached a stage where I have and LCD connected, a keypad, capturing input from the keypad and have been playing around with SEROUT with the intention of transmitting a byte or a few bytes wirelessly.
    To begin testing (after playing around with serout) I have interconnected my two pics (16f887 and 18f4520) by mean of wires.
    Like this :
    PIC 16f887 PIC 18F4520
    PORTC.6(TX)-----PORTC.7(RX)
    PORTC.7(RX)-----PORTC.6(TX)

    I have setup my code to send "key pressed or received value is" as a loop text string using serout from
    PIC 16f887 to the 18f4520.
    Code:
    loopy:
    high LED ' First LED on
            Pause 1000       ' Delay for .5 seconds
    	low led
             Pause 1000       ' Delay for .5 seconds
              SerOut PORTC.6,T2400,["are you receiving this tx from 16f887 ",datatx]
            pause 1000
               Goto loopy  ' Go back to loop and blink LED forever
            End
    The 18f4520 is set to receive using serin
    Code:
    SerIn PORTC.7,T2400,DataRX
    I press a key on the 4x4 keypad connected to the 18f4520,
    the keypress is stored as a variable (myvar) and myvar is made to equal datatx)
    I then display datatx (the keypress) on the lcd)
    Then I fetch the input (RX) from the other PIC using SERIN
    The input is held in variable datarx.
    I then display datarx on the LCD

    Once that's done I send the same variable datarx to the PC's com port using serout.

    And end off with the string "end of transmission" on LCD.
    I then use the serout line

    Well .... it works.

    Problem is it only happens once ! yes one time and then LCD goes blank and no matter how many keystrokes I press nothing else happens :-(

    So.... I think perhaps the serout/serin where my problems lie.
    Maybe full RX buffers or something else.
    Maybe I'm not passing the variables correctly.

    I would really appreciate if somone could have a quick look at my code and possibly tell me what I am missing or doing wrong.

    Kind regards

    Dennis

    Here is the code for each PIC
    PIC16f887
    Code:
    '*************************************
    'Transmit to PIC 18f4520 serout loop
    '*************************************
     '@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
     
    'Ocsillator selections here
      'OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz
    '        OSCCON = %01110001           'Int CLK 8MHz
    '        ANSEL= %11111111       '$0F = disable A/D converter
    '        option_reg = 7     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
     '       define osc 8        '8MHz
    'END of timer/oscillator defines
    'clear the ports
    
    
    
    OSCCON = %01110001          'Int CLK 8MHz
    ANSEL = %00000000           'All digital
    OPTION_REG.7 = 0            'Weak pull-ups enabled
    
    DEFINE OSC 8                '8MHz
    PORTA=0
    PORTB=0
    PORTC=0
    PORTD=0
    PORTE=0
    'end of port clear
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111    <<   'All pins are outputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10000000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
                       
    'variables begin here
            myvar var byte
            datatx var byte
            datarx var byte
    'end of variables
    
    
    LED var PORTd.0   ' Alias PORTD.0 to LED
    
    
        
    loopy:
    high LED '  LED on
            Pause 1000       ' Delay for .5 seconds
    	low led 'LED off
             Pause 1000       ' Delay for .5 seconds
              SerOut PORTC.6,T2400,["are you receiving this tx from 16f887 ",datatx]
            pause 1000
               Goto loopy  ' Go back to loop and blink LED forever
            End
    'End of all code
    PIC 18F4520
    Code:
    '*************************************
    'Keypress display on LCD and TX to wherever
    '*************************************
    
    'Ocsillator selections here
            OSCCON = $70            'Int CLK 8MHz
            OSCTUNE.6 = 1           'PLL 4x
            ADCON1= %00001111       '$0F = disable A/D converter
            cmcon   =   7 
            INTCON2.7 = 0     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
            DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << tris bit order numbering
    'TRISA = %11111111       'All pins are outputs
    '// Define port pins as inputs and outputs ...
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10000000
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
                       
    'variables begin here
            myvar var byte
            datatx var byte
            datarx var byte
    'end of variables
    
    'LCD defines begin here   
            DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
            DEFINE LCD_DREG PORTD 	'defines the port where data lines are connected to
            DEFINE LCD_DBIT 4 	'defines the position of data lines for 4-bit interface (0 or 4)
            DEFINE LCD_RSREG PORTD 	'defines the port where RS line is connected to
            DEFINE LCD_RSBIT 2 	'defines the pin where RS line is connected to 
            DEFINE LCD_EREG PORTD 	'defines the port where E line is connected to 
            DEFINE LCD_EBIT 3 	'defines the pin where E line is connected 
            'DEFINE LCD_RWREG 0 	'defines the port where R/W line is connected to (set to 0 if not used)
            'DEFINE LCD_RWBIT 0 	'defines the pin where R/W line is connected to (set to 0 if not used)
            DEFINE LCD_COMMANDUS 2000 	'defines the delay after LCDOUT statement 
            DEFINE LCD_DATAUS 200 		'delay in micro seconds
    'END of LCD DEFINES
    
    'includes begin here
            INCLUDE "modedefs.bas"
            include "c:\pbp\samples\keypad.bas"
    'end of includes
    
    'Keypad code begins here
            DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
            DEFINE KEYPAD_ROW_PORT   PORTB    ' ROW port = PORTB
            DEFINE KEYPAD_ROW_BIT    0        ' ROW0 = PORTB.4
            DEFINE KEYPAD_COL        4        ' 4 COL keypad
            DEFINE KEYPAD_COL_PORT   PORTB    ' COL port = PORTB
            DEFINE KEYPAD_COL_BIT    4        ' COL0 = PORTB.0
            DEFINE KEYPAD_DEBOUNCEMS 200      ' debounce delay = 200 mSec
            DEFINE KEYPAD_AUTOREPEAT 1        ' use auto-repeat feature
    'end keypad code
    
    'Main code begins here       
    
            Pause 2000       ' Wait for LCD to startup
    start:
            'read keypress variable 
            @ READKEYPAD _myvar 
            LOOKUP  myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress
            datatx = myvar 'pass the variable to solve strange character problem
            lcdout datatx 'display the variable on the LCD
                
            lcdout $fe,1          'clear lcd screen
       'receive section 
             SerIn PORTC.7,T2400,DataRX  'receive data from other pic (16f887) and store as variable datarx    
             LCDOUT datarx          'displays data received from serin datarx
             pause 2000             
             lcdout $fe,1          'clear lcd screen
        'receive section ends
        
       
       'transmit section
            'send datarx(received data from toher pic) to pc serial port 
            serout PORTC.6,T2400,["the key pressed or received value is ",datarx] 'SerOut PinNumber2,T2400,DataRec (FIXED!!
            pause 1000
       'transmit section ends
            LCDout "end of transmission"
            lcdout $fe,1          'clear lcd screen
            
    goto start
    
    'End of all code

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


    Did you find this post helpful? Yes | No

    Default

    A little history to get you started...
    http://www.picbasic.co.uk/forum/show...highlight=idle
    let us know if the above helps.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default ok .... now my options ?

    Hi Dave

    thanks for the history lesson re serin ..very informative ...
    The posting was a little confusing in that (unless I missed it!) it is not clear on how to get the port to dile low IDLE high or IDLE low.
    Is is as simple as somthing like
    portX.Y low or high after the serin line ?
    Note that I am not sending anything over RF yet ... the two PIC's are just wired together at this stage.

    Should I rather try DEBUG or serin/out 2 ?
    Do they suffer from the same issues?

    I would like to make sure I get everything ready before I attach the wireless RF and TX , maximizing both power and rate on the TX/RX pairs, other wise why bother ...not so ?

    Any further help would be much appreciated :-)

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    For PIC to PIC Debug is not the way. SERIN is good for basic stuff. SERIN2 has a whole lot more options and uses the same syntax as HSERIN when you need it. The nice thing about the SERIN/2 is it can be set for TRUE or INVERTED while HSERIN is TRUE only requiring an inverter to connect to things like a PC, but that is a minor thing with the other benifits of hardware serial.

    http://www.melabs.com/resources/samples.htm
    Scroll down to the ser2mod examples for...examples....

    When it comes time to idle low or high that can be done with a resistor 100K. Or in your code.
    Dave
    Always wear safety glasses while programming.

  5. #5


    Did you find this post helpful? Yes | No

    Default OK so suggested method for TX RX is of choice is ...

    SERIN2
    or
    HWSER right ?

    You mentioned being able to set the IDLE in software if I am going to be using SERIN...
    That's what I was asking in the last post :-)

    In the post you pointed me to it mentions the issues/problems with SERIN and to set it IDLE ...
    SO my question is how do you set the IDLE using software ?

    Is there a document regarding the IDLE setting methods ?

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Normally the mode takes care of the idle state
    http://www.picbasic.co.uk/forum/show...92&postcount=7
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I hate to sound like a broken record - but... Always use the hardware serial port if your device has one. You will be glad you did.
    Charles Linquist

  8. #8


    Did you find this post helpful? Yes | No

    Default hmm...

    Thanks Dave and Charles :-)

    But where do I start with hardware ports?

    I got the impression reading through the forums that software serin/out and serin2/serout2 and debug would be easier to play around with.
    I ssetting up the hardware option just as easy ?

    I also read somewhere that serin needs to be setup to look for something first before it starts accepting data ? Is this why I after one keypress, nothing else appears on the LCD ?

    Is there a some code I could use just to test the TX/RX function between 2 PIC's using wires ( see my diagram in earlier posts) , once I have that working I can then move onto TX and RX using wireless

    Something like setup PIC A to send a string or a byte to PIC B and then have PIC B send the same byte to hyperterminal(pc).

    Could I use serin2 first then serout (not serout2) to send the string or byte to hyperterminal(pc).

    Have I made the correct choice for send and receive ports ..on both pics PORTC.6 and PORTC.7

    Any help or advice would really be appreciated.

    Kind regards

    Dennis

  9. #9
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default RS232 Comms

    Dennis,

    A few thoughts on linking PICs by RS232:

    1. I've done it - unfortunately, deleted the code after getting it working.

    2. I used SERIN2 and SEROUT2, by habit rather than for good technical reasons.

    3. HSEROUT/HSERIN do pass much of the processing down to the chip hardware and save lots of processing time and code space. However, if you are still in the 'getting something working stage' I'd use SEROUT/SERIN to avoid additional DEFINES and so on needed for HSEROUT/IN.

    4. I've had a short read through your code and not spotted any problems. I'd suggest that you temporarily abandon the keypad business and write a very basic routine to send/receive one byte variable PIC-Hyperterm and then PIC-PIC. Start using SEROUT/SERIN then move on to SEROUT2/SERIN2 and then HSEROUT/HSERIN.

    5. Have you got carriage returns (Decimal '13') at the end of each transmission?

    6. I've not looked up the data for your chips but what is TRISX?

    7. Just had a longer look at the code and I think your sequencing is wrong? Should be:

    a. PICA. Press key
    b. PICA. Send to the other PIC (I think you receive here?)
    c. PICB. Receive data
    d. PICB. Send data
    e. PICA. Receive data
    f. PICA. Display data on LCD
    g. PICA. Press key......

    Watch those CRs!

    8. I assume that each end of the PIC to PIC RS232 link is symetrical i.e both have RS232 chips for level conversion or both do not?

    Regards Bill legge

  10. #10


    Did you find this post helpful? Yes | No

    Default thank you Bill

    Hi Bill

    Thanks a million for the informative response and advice :-)
    Here is my reply to your examination :
    1.Damn, just my luck ! Nice to hear you came right though :-0
    2.I wouldn't mind using either have those but found issues with serout2 and the data displayed in hyperterminal so used serout.
    What are your thoughts on using DEBUG ?
    3.I did notice in reading through other forum posts and the manual that DEFINES are required.
    4.I was thinking of doing exactly the same thing just to remove also possible room for error :-)
    5. No I do not have carriage returns at the end of each transmission are you referring to 10,13 at the end of serout ?
    I was under the notion that I could just SEROUT ping and port at 2400T and the variable name all in a loop.... is this where my problem is...apart from being a little rusty and having to re-live been a PIC newbie again ?
    6.TRISX is a very secret register which you enable my moving the shift in the time space continum on a PIC 18f4520 ....:-) lol just kidding.
    OK jokes aside TRISX is the comment I placed there so that I could remember how to manipulate TRIS for IO.
    7. Sequencing is correct ...just realised I have not added the connection diagram :-( will add it to this post now.
    I am sending from PIC 16f887 PIC 18F4520
    PORTC.6(TX)-----PORTC.7(RX)
    PORTC.7(RX)-----PORTC.6(TX)
    so it's PIC16F887 >>PIC18F4520 >>PC(hyperterminal)
    out in | out
    TX RX | TX
    |
    LCD IS HERE (wired to 18F4520)
    Once again ...where are the CR's and where should they go exaclty ?
    8.The only place there is a MAX232N is on the TX side of the 18F4520 so that is can connect to PC serial port, in which case I am able to send and receive data to and from the PC :-)

    Hope this helps , will post more info just now to make it simpler to read ;-)
    Any more info would be much appreciated.

    Kind regards
    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Just to add to the confusion...
    DEFINES are not required.
    Demo:
    Code:
    X   VAR BYTE
    START:X = X + 1
    HIGH PORTD.2 :PAUSE 250:LOW PORTD.2:PAUSE 250
    RCSTA=$90:TXSTA=$24:SPBRG=129:HSEROUT ["HSER ",DEC X,13,10]
    PAUSE 250:RCSTA=$0:SEROUT2 PORTC.6,84,["SER ",DEC X,13,10]
    GOTO START
    Sometimes complete control is handy.
    Dave
    Always wear safety glasses while programming.

  12. #12


    Did you find this post helpful? Yes | No

    Default smoke and mirrors ...?

    Hi Dave ...how are you ?

    Mmmm that sure got me :-)

    An here I am still trying to at least get some comms going :-( !

    I have the champagne ready ...now just to find the ship to smash it open on and the people to join my 'I can finally TX/RX' between PIC's celebrations...

    All I can say for now is... WATCH THIS SPACE ! LOL

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Smoke and mirrors???


    Here is a simple example to build on

    SEND:
    Code:
    SEROUT PORTC.4,T2400,[9,3]
    RECEIVE:
    Code:
    SERIN PORTC.4,T2400,[9],net
    
    IF net = 3 THEN DO_SOMETHING
    Connect VSS and the two PIC pins together.
    Dave
    Always wear safety glasses while programming.

  14. #14


    Did you find this post helpful? Yes | No

    Default ok....just another question ...

    Dave

    Will try the operation with only your code...
    Can one run SERIN and SEROUT on same pic as I would like to send the received data to hyperterminal and also to the LCD. So would the fol.lowing code be correct then ?
    Oh and why did you choose PORTC.4 ? Looking at the pinouts for both pics I see PORTC.6 is TX and PORTC.7 is RX -are these for hardware serial , ie. HSERIN and HSEROUT and should I use them for SERIN and SEROUT or is it better to use PORTC.4 in case I want to use them for HSERIN/OUT later ?

    Here's the code

    Transmitter PIC (16F887)
    Code:
    SEROUT PORTC.4,T2400,[9,3]
    Receiver PIC (18F4520)
    Code:
    main:
    
    SERIN PORTC.4,T2400,[9],net 'prepare to receive the data from other PIC
    IF net = 3 LCDOUT "data is",net 'look for the number 3
    SEROUT PORTC.5,T2400,[9,3] 'send received data to hyperterminal via max232n to PC
    end if 
    goto main 
    end
    Smoke and mirrors indeed :-)

    Kind regards

    Dennis
    Last edited by Dennis; - 26th November 2009 at 22:51.

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


    Did you find this post helpful? Yes | No

    Default

    I went with PORTC4 for no good reason other than to show that the bit banging routines work on most any pin. You are correct about HSERN only working on the hardware pins.

    What I can see of your code(using phone) it looks like it should work.
    Dave
    Always wear safety glasses while programming.

  16. #16


    Did you find this post helpful? Yes | No

    Default Thanks Dave

    Dave

    Thanks a million for the feedback

    Will try it right away and feedback asap :-)

    Kind regards

    Dennis

  17. #17


    Did you find this post helpful? Yes | No

    Default it works :-)

    Hi Dave

    Good news and a big thank you !!
    It's working...
    I am transmitting from 16F887 to 18F4520 and then from 18F4520 to and LCD and to PC serial port.

    One tiny issue I have is with the serin command.
    It displays a string fine but the variable is always a wingdings character unless I use a lookup ...(see my code below for serout on receiver)
    So I have three questions now ....
    1. Is there any way to set the serin command to send the variable (net) in the code example so that it appears as the number 3 ?
    2.Could you possibly show me a code snippet to accomplish the same thing using debug and also hser please
    3. Bearing in mind I want to eventually to accomplish all of this using RF modules, and may decide to use hserin/out ,and all I want to do is relaible transmit 3 or possible 4 bytes, would I have to use an external oscillator or would the internal suffice ?

    Kind regards
    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Try
    DEC net

    OSCs..... Some will not agree but many times times the internal is not stable enough at higher baud rates to be reliable.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    To set DEBUG up
    Code:
        DEFINE DEBUG_MODE  0    ' Debug sending TRUE serial data
        DEFINE DEBUG_REG PORTC  ' Debug Port = PortC
        DEFINE DEBUG_BIT 4      ' Debug.bit = PortC.4
        DEFINE DEBUG_BAUD 2400  ' Default baud rate = 2400
    Send
    Code:
    DEBUG 9,3
    Receive
    Code:
    DEBUGIN [WAIT("9"),DEC net]
    The same syntax works for HSERIN/OUT
    Dave
    Always wear safety glasses while programming.

  20. #20


    Did you find this post helpful? Yes | No

    Thumbs up the long 'WAIT' .....

    Hi Dave :-)

    How are you ?

    Tried the code exactly as you suggested ...

    On the receiver end it seems like debug is just WAITing forever to receive the number 9 match but it never seems to get it, so that's where the program stops.
    I thought it might be the order of the numbers so I changed their order but that didn't fix the problem.

    Is it possible that the problem could be on the receiver PIC as I still have a serout line to send the data to the PC serial port to view in hyperterminal.
    Is it ok to run debug and serin in the same PIC ( wondering if this is a silly question) or should I use debug to transmit to hyperterminal as well ?

    Could the problem be that I have the DEFINE statements in the wrong place ? I noticed an extra space character in the code snippet you posted between mode and 0 .. removed that and recompiled but still no joy :-(

    Any suggestions ?

    Here's the code :
    Receiver
    Code:
    'debug defines begin here - necessary for degug operation
        DEFINE DEBUG_MODE 0    ' Debug sending TRUE serial data
        DEFINE DEBUG_REG PORTC  ' Debug Port = PortC
        DEFINE DEBUG_BIT 4      ' Debug.bit = PortC.4
        DEFINE DEBUG_BAUD 2400  ' Default baud rate = 2400
        'debug defines end here
        
    'Main code begins here       
    
            Pause 2000       ' Wait for LCD to startup
            
    test:                                                         
            lcdout $fe,1 
                    lcdout "starting tx rx"
         '*******************************************           
        '*SERIN PORTC.4,T2400,[9],net 'prepare to receive the data from other PIC
        '*this lines works perfectly to send data
         '*******************************************
         '
         '****heres the same thing using debugin (RX)- check/adjust defines for settings
         DEBUGIN [WAIT("9"),DEC net]
         '****end of debug line
        lcdout "rx complete"
        pause 1000
        lcdout $fe,1 'clear lcd screen
    IF net = 3 then 
        lcdout $fe,1 
        LCDOUT "data is ",dec net 'look for the number 3 
        pause 2000
    endif  
        lcdout $fe,1
        lcdout "begin serout to hyperterminal"
        pause 1000
        LOOKUP  net,[0,"123A456B789C*0#D"],net 'use lookup table to diplay proper display in hyperterminal
    ' send net variable to hyperterminal using serout 
        serout PORTC.3,T2400,["the key pressed or received value is ",net,10,13] 
        lcdout $fe,1
        goto test
    end
    Transmitter
    Code:
    'debug defines begin here
        DEFINE DEBUG_MODE 0    ' Debug sending TRUE serial data
        DEFINE DEBUG_REG PORTC  ' Debug Port = PortC
        DEFINE DEBUG_BIT 4      ' Debug.bit = PortC.4
        DEFINE DEBUG_BAUD 2400  ' Default baud rate = 2400
        'end of debug defines
    
    LED var PORTd.0   ' Alias PORTD.0 to LED
    
    
        
    loopy:
    high LED '  LED on
            Pause 1000       ' Delay for .5 seconds
    	low led 'LED off
             Pause 1000       ' Delay for .5 seconds
             '*this serout lines works perfectly :-)
             'SEROUT PORTC.4,T2400,[9,3]
                       '**another example - SerOut PORTC.6,T2400,["are you receiving this tx from 16f887 ",datatx]
            'DEBUG line starts here
            DEBUG 3,9
            'end of debug line
            
            pause 1000
               Goto loopy  ' Go back to loop and blink LED forever
            End
    'End of all code

  21. #21


    Did you find this post helpful? Yes | No

    Default a change in the code ...

    Hi again Dave

    Thanks for your help so far , I really am learning a lot :-)

    To double check that nothing on the circuit had changed I loaed the code for the serin and serout examples from earlier and all still works , which tells me the problem has something to do with the debug code.

    Reading through the help and forums and manual I noticed that DEBUGIN requires it's own set of defines .
    I'm still checking to see if the baud rate must be defines eg. debugin_baud ..which I tried anyway and the compiler didn't complain.
    So I tried it the code again with the updated degug statements but still no joy :-(

    Here's the updated receiver code:
    Receiver
    Code:
     'debugin defines
        DEFINE DEBUGIN_REG PORTC      ' Set Debugin port
        DEFINE DEBUGIN_BIT 4          ' Set Debugin pin bit
        DEFINE DEBUGIN_MODE 0         ' Set Debugin mode: 0 = true, 1 = inverted
        Define DEBUGIN_BAUD 2400      'set Debugin baud rate
        'Debugin defines end here
    'debugin commands end here
    
    'debug defines begin here - necessary for degug operation
     '   DEFINE DEBUG_MODE 0    ' Debug sending TRUE serial data
     '   DEFINE DEBUG_REG PORTC  ' Debug Port = PortC
     '   DEFINE DEBUG_BIT 4      ' Debug.bit = PortC.4
     '   DEFINE DEBUG_BAUD 2400  ' Default baud rate = 2400
        'debug defines end here
        
    'Main code begins here       
    
            Pause 2000       ' Wait for LCD to startup
            
    test:                                                         
            lcdout $fe,1 
                    lcdout "starting tx rx"
         '*******************************************           
        '*SERIN PORTC.4,T2400,[9],net 'prepare to receive the data from other PIC
        '*this lines works perfectly to send data
         '*******************************************
         '
         '****heres the same thing using debugin (RX)- check/adjust defines for settings
         DEBUGIN [WAIT("9"),DEC net]
         '****end of debug line
        lcdout "rx complete"
        pause 1000
        lcdout $fe,1 'clear lcd screen
    IF net = 3 then 
        lcdout $fe,1 
        LCDOUT "data is ",dec net 'look for the number 3 
        pause 2000
    endif  
        lcdout $fe,1
        lcdout "begin serout to hyperterminal"
        pause 1000
        LOOKUP  net,[0,"123A456B789C*0#D"],net 'use lookup table to diplay proper display in hyperterminal
    
        serout PORTC.3,T2400,["the key pressed or received value is ",net,10,13]
        lcdout $fe,1
        lcdout datatx
        pause 1000
        goto test
    end
    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Try
    DEBUG "9",DEC 3
    Dave
    Always wear safety glasses while programming.

  23. #23


    Did you find this post helpful? Yes | No

    Default nope :-(

    tried it ...still no joy

  24. #24


    Did you find this post helpful? Yes | No

    Default

    Dave ...

    Do I need the defines on the receiver for debugin ???

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


    Did you find this post helpful? Yes | No

    Default

    Yes, you need DEBUGIN and DEBUG defines.

    I am giving you this stuff from memory and evidently I have forgotton something. When I get back to the shop tonight I will test it and see what I am missing.

    Maybe someone will fill in my blanks
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    The send code
    Code:
        DEFINE DEBUG_MODE  1    ' Debug sending INVERTED serial data
        DEFINE DEBUG_REG PORTB  ' Debug Port = PortC
        DEFINE DEBUG_BIT 3      ' Debug.bit = PortC.4
        DEFINE DEBUG_BAUD 2400  ' Default baud rate = 2400
    
    DEBUG "9",DEC 3,$d,$a
    The receive code
    Code:
        DEFINE DEBUGIN_MODE  1    ' Debug sending INVERTED serial data
        DEFINE DEBUGIN_REG PORTB  ' Debug Port = PortC
        DEFINE DEBUGIN_BIT 4      ' Debug.bit = PortC.4
        DEFINE DEBUGIN_BAUD 2400  ' Default baud rate = 2400
    
    DEBUGIN [WAIT("9"),DEC NET]
    I just ran this in real life, it works.
    Sorry for giving it wrong before.
    Dave
    Always wear safety glasses while programming.

  27. #27


    Did you find this post helpful? Yes | No

    Default pssst Dave .....

    IT WORKS !!!
    WOOOOOOHOOOOOOOOOO you ROCK ! :-)

    Thank you thank you thank you :-)

    By the way that memory of yours was pretty damn close :-)
    Seems inverted mode was needed ?

    What are the $d and $a for in the line below by the way ?

    Code:
    DEBUG "9",DEC 3,$d,$a
    And now for HSERIN and OUT

    A few questions first ..

    1. With HSERIN and OUT , is it a necessity to use the onboard TX/RX pins , in my case PORTC. and PORTC.7 ?

    2. Is it pretty much a case of replacing the debug lines with HSERIN as you said in a n earlier posting ?

    Thanks again Dave

    Dennis

  28. #28
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Hello Dennis,

    I don't know if Dave is online now, so I thought I'de jump in and answer your 2 questions real quick...As Dave has helped me immensely on the same serial in out topic...Thanks again Dave!

    1) The $d $a is a "Carriage Return - Line Feed" terminator
    2) Yep, the hardware ports have to be used for HSERIN/OUT.

    Hope I helped and didn't offend you Dave

    Enjoying this thread, and learning from it too!

    Chris

  29. #29


    Did you find this post helpful? Yes | No

    Default Hey Chris

    Thanks so much :-)

    I really appreciate it :-)

    I haven't tried it yet as I was awaiting Dave's instruction and possibly a code snippet.
    The reason for this is that I like to having a working reference first and then experiment.
    I have learned that by doing the wrong things first you battle even more and as the late nights roll by you find your concentration span dwindling more and more no matter how excited or motivated you are.
    Not only that, you also find it's so frustrating and de-motivating when things just don't work and you'd like to get on with the next step but you can't because something you have done incorrectly (something as small as a character in the wrong place) is holding you back.Even if someone just points you to a document or flames you for putting the code in the wrong place without the code tags. You learn from this ..logical baby steps count !

    It is so nice to have the chance to be involved with such a helpful community who share a common interest. I long for the day when I too have strong enough 'code eyes' and experience to also help others here :-)
    Thank you all !!

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Hope I helped and didn't offend you Dave
    This is a community effort, the more giving the better.
    And it is kinda hard to offend me anyways

    yup, the DEBUG and HSER syntax is pretty much the same. The DEFINES are different and like Chris said the hardware pins have to be used.

    Earlier in this thread I gave an example of using HSER with out DEFINES but for most cases I do use them. Start that way.

    If are are going to communicate with a PC and/or some other things an inverter setup is needed, RS232 chips are mostly used for this.

    There are some calculations needed for the DEFINES and I cheat by using this
    http://www.picbasic.co.uk/forum/showthread.php?t=4994

    I am not at my machine again and I learned my lesson about going from memory so no snippets from me at this time. Chris??? Do you have one to get him started???
    Dave
    Always wear safety glasses while programming.

  31. #31


    Did you find this post helpful? Yes | No

    Default fading memory is better than no memory !

    Dave ..

    Thanks again, but fading memory is better than no memory ( lol or is it ?)

    So even if it's wrong it will send me hurtling off in the HSER direction on a voyage of discovery and when I'm truly stumped I will ask for assistance then and only then !

    Kind regards

    Dennis

  32. #32


    Did you find this post helpful? Yes | No

    Default Awesome

    What an awesome calculator proggie ;-)

    A true GEM !

    Thanks a million

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Thank mister e for the MultiCalc, I use it often.

    http://melabs.com/resources/samples/pbp/usart.bas
    Play with the above to get started with the USART. Notice they did not use DEFINES.

    The program will echo your keyboard with one PIC connected to a PC. The terminal program that is part of MCS is good for this setup. I think the above sample is for 4Mhz. So check the values with MultiCalc.

    Keep us posted...
    Dave
    Always wear safety glasses while programming.

  34. #34


    Did you find this post helpful? Yes | No

    Default oscillator setting

    Hi dave

    Thanks again :-)

    For my 16f887 i have the following set for using the internal clock
    Code:
    OSCCON = %01110001          'Int CLK 8MHz
    ANSEL = %00000000           'All digital
    OPTION_REG.7 = 0            'Weak pull-ups enabled
    
    DEFINE OSC 8                '8MHz
    So I use 8 MHZ not so ?

    For the 184520 the following is set
    Code:
    'Ocsillator selections here
            OSCCON = $70            'Int CLK 8MHz
            OSCTUNE.6 = 1           'PLL 4x
            ADCON1= %00001111       '$0F = disable A/D converter
            cmcon   =   7 
            INTCON2.7 = 0     'switch pull-ups ON
    'END of oscillator selections
      'timer/oscillator defines 
            DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
    So do I choose 4MHz or 32 MHz ?

    thanks a million

    Kind regards
    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    For the 887 use 8Mhz for the calcs.

    I am not sure about the 4520, I have not used USART with PLL enabled.
    But...
    I think the USART uses the primary OSC so try 4Mhz. 50 50 chance of it working
    Dave
    Always wear safety glasses while programming.

  36. #36


    Did you find this post helpful? Yes | No

    Default osciallator..

    Hi Dave

    Could I set both PICS to 4 MHz internal OSC ?
    And once it's working try variations ?

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


    Did you find this post helpful? Yes | No

    Default

    That would be the way to trouble shoot.
    Just make sure they are running at the expected speed with a blinky and a stop watch or meter if you have one..
    Dave
    Always wear safety glasses while programming.

  38. #38


    Did you find this post helpful? Yes | No

    Default ok...and now for the RF plunge :-)

    Hi again Dave

    I think I am almost ready for the next step ....
    RF and RF module TX RX
    I have been reading posts all through the forums, even some of yours from years back ...
    Now for the next step ... to try the same or a similar thing without the wires.

    Should I start off with sering or plunge straight into HSER ?

    The plan is to be able to send 3 bytes using the most reliable method.

    So the question is where do I start and what do I start with ?

    Kind regards
    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    So do I choose 4MHz or 32 MHz ?
    I have it on good authority that the PLL speed is the one to use. Thanks Bruce!!!

    What radio modules are you using? I have only used the ones from rentron.com.

    As for reliability, all of the serial methods (HSER,SER,SER2..) are good. Are you planning to use interrupts with the serial input or just wait and time out, check later sort of thing?
    Dave
    Always wear safety glasses while programming.

  40. #40


    Did you find this post helpful? Yes | No

    Default ok here goes

    Hi Dave

    :-)

    So are you saying I should use 8MHz OSC and 4x PLL for the 18F4520 and use 32 MHz when I do the HSER DEFINE calculations then ?
    And on the 16F887 use it's max INTOSC which is 8 MHZ for the HSER calculations ?
    OR....
    set both PIC's at 4 or 8 MHz and then calculate the HSER DEFINEs accordingly ?

    Something like this maybe
    Code:
    ‘For 8MHz @ 2400bps
    
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 51  ' 2400 Baud @ 8MHz, 0.17%
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 51  ' 2400 Baud @ 8MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    ‘For 4 MHz @ 2400bps
    
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 25  ' 2400 Baud @ 4MHz, 0.17%
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 25  ' 2400 Baud @ 4MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    A quick question here ...
    Which comes first ... DEFINE's or register settings ?

    Chat soon

    Dennis

Similar Threads

  1. Direct PIC to PC without MAX232
    By acjacques in forum Serial
    Replies: 14
    Last Post: - 23rd October 2014, 22:32
  2. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 01:52
  3. PIC or xbee times out after Tx 504 bytes
    By archendekta in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd November 2009, 09:45
  4. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 15:46
  5. RX TX modules - intermitent communication
    By ruijc in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2009, 01:13

Members who have read this thread : 3

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