Auto Downloads


Closed Thread
Results 1 to 13 of 13
  1. #1
    TONIGALEA's Avatar
    TONIGALEA Guest

    Default Auto Downloads

    Hello Everyone
    i am making a data logger which stores data to a serial eeprom.
    i want to know how i can make my data logger go into download mode when i plug the 9 Way D type cable to a PC
    i am using Hardware uart on the PIC16f877 and i can use Hserout to download the data stored to my eeprom by pressing a push button which then jumps to my download sub.
    The problem is that the unit the logger is going into would not have a push button the user should be able to go into download mode when the pc cable is plugged in.
    How can i do this?
    Also because i would also be using a bootloader is there a way of doing this with just 3 wires TX,RX & Gnd/


    Toni

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you have control over the PC application, then have it ping the data logger (sending an occasional byte) until the logger responds.

    On the PIC side, simply test RCIF on occasion to determine if the PC has been connected, the ping byte has been received, and the RCREG holds something.

    The USART can handle all this in the background, and your main code can do whatever until the PC is connected.

    Code:
    Y       VAR byte    ' Inbound data recovered from RCREG
    RCIF    VAR PIR1.5  ' USART received character interrupt flag bit
    CREN    VAR RCSTA.4 ' USART continuous receive enable bit
    OERR    VAR RCSTA.1 ' USART over-run bit
    
    INTCON  = 0      ' Disable interrupts (just using flags)
    ADCON1 = 7      ' A/D off
    
    TRISB.0 = 0     ' Set RB0 to output
    PORTB.0 = 0     ' LED off (indicates data was in RCREG)
       
    Main:
        IF RCIF THEN Have_Data ' If RCIF=1 there's data in RCREG
        HIGH 1          ' so jump to Have_Data and send your EEPROM
        PAUSE 1000      ' contents
        LOW 1
        PAUSE 1000      ' Long pauses show how RCREG receives data
        GOTO Main       ' in the background
            
    Have_Data:          ' Send your EEPROM data here
        PORTB.0 = PORTB.0 ^ 1 ' Toggle RB0 to indicate data rcvd
        WHILE RCIF            ' Empty RCREG by reading it
         Y = RCREG
        WEND
        ' If OERR = 1 then the over-run bit is set and we need to clear it
        ' to re-enable receive. If not, then carry on
        IF !OERR THEN  Main  ' If no over-run condition, return to Main
        CREN = 0             ' Over-run condition. Disable receive
        CREN = 1             ' Re-enable & clear OERR flag
        GOTO Main
    Last edited by Bruce; - 23rd September 2004 at 18:55.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    TONIGALEA's Avatar
    TONIGALEA Guest


    Did you find this post helpful? Yes | No

    Default

    Bruce
    Thank you very much for the time and effort you put into answering my questions.
    i tried the example you gave and it worked perfectly.
    the program goes to the Have_Data: sub when i sent any byte from the PC.
    Excellent !!

    BTW what does this line mean HIGH 1


    Toni

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Toni,

    You're welcome.

    < BTW what does this line mean HIGH 1

    HIGH & LOW are PBP commands to make the specified pin high or low. Both are explained in your PBP manual.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    TONIGALEA's Avatar
    TONIGALEA Guest


    Did you find this post helpful? Yes | No

    Default

    I do know that bruce
    what i was really asking is if High can be used in that way without the port pin
    example High portb.1 takes portb.1 to 5v
    High 1 what is the port pin ?

    Toni

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Tony,

    When you use the HIGH or LOW commands with numeric pin specifiers like 0,1,2,3 etc,, it starts from RB0, and continues on to RC7. With 0 being RB0 and 15 being RC7.

    Of course you can still use HIGH PORTB.0 too, but if you use the HIGH or LOW commands for port pins other than RB0 to RC7, then you can't use numeric pin specifiers.

    You would specify port pins like this -

    HIGH PORTA.0
    HIGH PORTA.1
    HIGH PORTD.1
    etc,,.

    If you specify an illegal bit # with one of these commands such as HIGH 16, PBP returns the error "illegal bit number".

    Using numeric pin specifiers like HIGH 0, LOW 0 rather than HIGH PORTB.0, LOW PORTB.0 comes in handy.

    Example;
    Code:
    X VAR BYTE
    
    MAIN: ' LED Light chaser on RB0 to RC7
        FOR X = 0 TO 15 ' Light LED's on RB0 to RC7
          HIGH X
          PAUSE 50
        NEXT X
        
        FOR X = 15 TO 0 STEP-1 ' Turn them back off
          LOW X
          PAUSE 50
        NEXT X
    
        GOTO MAIN
    Last edited by Bruce; - 24th September 2004 at 17:46.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Santana's Avatar
    Santana Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce
    i have learn't something from your reply to Toni
    i didn't know you could use numeric pin specifiers like 0,1,2,3 etc
    Thanks for the clearification
    Also with your auto download example that was great the only point i didn't like is that any byte sent from the pc activates to download.
    Is there a way were the auto download is started by a specific
    btye ?

    Keep Teaching Us

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Just test the value received to look for a specific character.

    Y = RCREG
    IF Y = ? THEN
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    Santana's Avatar
    Santana Guest


    Did you find this post helpful? Yes | No

    Default sleep with pic

    Hi Guys/Ladies
    What is the best way to put and wake my pic to sleep
    i am designing a data logger that would be battery operated
    and would date stamp my readings and store to a serial eeprom.
    Some people might want to take readings only once an hour
    and the reading only take a minute max .
    How can put the pic 18F452 to sleep then wake it up just before the user reading time.
    Would i need to use a RTC that can trigger an interupt on RB0 ?
    Just a few pointers in the right direction

  10. #10
    TONIGALEA's Avatar
    TONIGALEA Guest


    Did you find this post helpful? Yes | No

    Default Any other alternative

    Hi Bruce and others
    Sorry i have to come back to this topic again
    On my data logger i simply test RCIF on occasion to determine if the PC has been connected, this works ok
    But the problem is that the pic is aspleep 99% of the time and it dosen't responds to the ping when in sleep mode.
    i was going to use a link jumper to link a pin to gnd when the user needs to make configurations so that the pic test to see if this pin is 0v than jump over the sleep part of my code but the end user want everything done from the PC end
    is there a way i can do even if i have to use more than 3 wires for my serial connection


    Regards
    Toni

  11. #11
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Why not simply cross-connect your SERIN/HSERIN pin additionally with say RB0 (or any of RB1-4), and when there's any serial activity it'll wake the PIC from sleep. Actually, doesn't the USART have that abaility too...

  12. #12
    TONIGALEA's Avatar
    TONIGALEA Guest


    Did you find this post helpful? Yes | No

    Default

    I didn't think that the Uart could do this when in sleep mode

  13. #13
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Just double-checked, it does, but only in sync-slave mode... OK, so back to the idea of cross connecting your USART pin with one of the PortB pins to wake on status change. There's nothing in the rules that says you can't connect your input to more than one PIC pin.

Similar Threads

  1. How powering PIC in auto ?
    By fratello in forum Schematics
    Replies: 19
    Last Post: - 19th October 2009, 07:35
  2. auto recloser ELCB
    By badbaik in forum mel PIC BASIC
    Replies: 5
    Last Post: - 5th February 2009, 13:54
  3. AUTO baud rate detection FOR UART connection to PC
    By mike20200 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd September 2007, 00:56
  4. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 02:17
  5. Modem Auto Answer-Hanging for 1 min...
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 22nd August 2005, 09:38

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