Communication between two PicChip


Closed Thread
Results 1 to 29 of 29

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default Communication between two PicChip

    hello,

    I am trying to transfer data from one Pic16F88 to another F88 chip. is there a method better then the other one. I only have 4 ports left (one is use for adcin, one for ground between the two chips and two for serin and serout). The only alternative I know but would cost a bit more is to use an external EEPROM..
    I have A master program and a Slave program, here is the code, I think it is self explanatory:
    PortB.7 is hooked up to the PortB.0 (interrupt) of the other chip

    Master:
    Code:
      SetRTCTime = 125
      ViewTime = 0
    
            I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]  
            Pause 30
       
    
    serout portb.7, n2400, [$55, $55, $55, $55, $aa, SetRTCTime, ViewTime, StartTimeHour ]
    serout portb.7, n2400, [StopTimeHour, StartTimeMin, StopTimeMin, RTCYear, RTCMonth, RTCDay, RTCHour, RTCMin ]
    Pause 100
    
                lcdout $FE,1,  "upload Time Int"
                lcdout $FE,$C0, "Completed"
                pause 1500
                
    Return
    Slave:
    Code:
    '/////////////////////////////
    '/////// MyInterrupt  ////////
    '/////////////////////////////
    DISABLE
    MyInterrupt:
    
    waitfor55:
    serin portb.0 , n2400 , temp : if temp <> $55 then goto waitfor55
    
    waitforaa:
    serin portb.0 , n2400 , temp : if temp <> $aa then goto waitforaa
    
    serin portb.0, n2400, SetRTCTime : serin portb.2, n2400, ViewRTCTime
    serin portb.0, n2400, StartTimeHour : serin portb.2, n2400, StopTimeHour
    serin portb.0, n2400, StartTimeMin : serin portb.2, n2400,StopTimeMin
    serin portb.0, n2400, Year : serin portb.2, n2400, Month
    serin portb.0, n2400, Day : serin portb.2, n2400, Hour 
    serin portb.0, n2400, Minute
    
    If (SetRTCtime = 125) then
        I2CWRITE SDApin,SCLpin,$D0,$00,[$00,Minute,Hour,$00,Day,Month,Year,$00] ' Write to DS1307 to initialize a new time
        pause 30
    Endif
     
    If (ViewRTCTime = 55) then
        I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]  
        Pause 30
        
    serout portb.7, n2400, [$55, $55, $55, $55, $aa, SetRTCTime, ViewTime ]  'if 222 then
    pause 200
    
    serout portb.7, n2400, [$55,$55,$55,$55,$55,$aa,RTCYear, RTCMonth, RTCDay, RTCHour, RTCMin, RTCSec]
    serout portb.7, n2400, [StartTimeHour, StopTimeHour, StartTimeMin, StopTimeMin]
    pause 100
    
    Endif
    
    
    INTCON.1 = 0   ' Enable external Interrupt
    RESUME
    ENABLE                ' Enable Interrupt
    The problem now is that the information is not transfering. And this is not a method to get a ACK and verify information transfered.

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


    Did you find this post helpful? Yes | No

    Default Re: Communication between two PicChip

    I think you are crazy to not use the HARDWARE serial port. That would make things almost trivial. Is there some reason why you aren't using it?
    Charles Linquist

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Communication between two PicChip

    Its takes three pins from my chip
    : Serial Data Out (SDO) RB2/SDO/RX/DT
    • Serial Data In (SDI) RB1/SDI/SDA
    • Serial Clock (SCK) RB4/SCK/SCL

    I am already using SDA and SCL to program and read my RTC. Unless I can use the same pin for both..

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


    Did you find this post helpful? Yes | No

    Default Re: Communication between two PicChip

    Why don't you use I2C also for the communication from pic to pic? Pic 16F88 can operate as slave, so you will give it an address and you will transfer all the data with I2CWRITE and I2CREAD, simpler than that! You can find a working code for I2C slave on the forum, I posted it sometime ago and I don't remember where is burried.

    Cheers

    Al.

    PS. I found it! http://www.picbasic.co.uk/forum/show...ight=I2C+salve
    Last edited by aratti; - 13th November 2011 at 23:17.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default Re: Communication between two PicChip

    When I mentioned hardware serial port, I was referring to TxD and RxD. Then you could use HSEROUT and HSERIN. Connect those two lines together on your PIC, and you can communicate at 9600 baud at least, on the internal oscillators.
    Charles Linquist

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Communication between two PicChip

    I just want to do a very simple communication at first, then I will work on better one. I am using the same code as i used a few ago for a project on mine. It was working fine at the time. I was using a different compiler and different software.
    I am trying to re-use that code. Now I have taken THE code I used and just removed the extra stuff in the programming that is not needed ( calculation from a wireless thermometer) here is my sending code:

    INCLUDE "modedefs.bas"
    OSCCON = %01110000 '8 Mhz
    Define OSC 8

    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    '/////////////////////////
    '// LCD configuration //
    '/////////////////////////

    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 0 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 6 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 500

    TRISB = %00000000

    count_remain var byte
    temperature1 var byte
    temperature2 var byte

    Mainloop:

    temperature1 =11: temperature2 =22
    count_remain =44



    lcdout $FE,1, "TempC: ", dec (temperature1) , ".", dec2 temperature2," ",$DF,"C"
    lcdout $FE,$C0, bin count_remain , ".","F"
    pause 400

    serout portb.2, n2400,[$55,$55,$55,$55,$aa,temperature1,temperature2,coun t_remain]

    lcdout $FE,1 : LCDOUT "second ", dec (temperature2 / 100) , ".", dec2 temperature1," ",$DF,"r"
    lcdout $FE,$C0, dec count_remain , ".","23"
    pause 400

    goto mainloop

    end
    and here is the receiving code:
    INCLUDE "modedefs.bas"
    OSCCON = %01110000 '8 Mhz
    Define OSC 8

    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    '/////////////////////////
    '// LCD configuration //
    '/////////////////////////

    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 0 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 6 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 500

    ADCON1 = %00100010

    encoded11 var word : encoded22 var word : encoded33 var word : encoded44 var word : encoded4 var byte
    count_remain var byte :temp var byte


    TRISA = %00000001 ' Set PORTA to all output
    TRISB = %00001111


    Mainloop:
    '23

    lcdout $FE,1 , "hello ", dec 105," ","C"
    lcdout $FE,$C0, "before"
    pause 300

    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
    serin portb.2, n2400, encoded22.HighBYTE


    lcdout $FE,1, "encoded11.HighBYTE", dec encoded11.HighBYTE , ".", dec2 encoded11.LowBYTE
    lcdout $FE,$C0, "TempF: ", "-", dec encoded22.HighBYTE , "After"
    Pause 300


    goto Mainloop

    end

    the sending code seems to work. but the receiving code seems to be stuck on the first LCDOUT, I guess it does not see the 55 or aa...

    k

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