PIC18F I2C Communication with Arduino


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: PIC18F I2C Communication with Arduino

    The data being sent is the value 0, that looks alright to me though I've literally never used I2CWrite.
    Check the pins you're using for multiplexed functions, specifically analog such as ADC and comparators and make sure the pins are set to digital.

    Then I'd check the pins with a scope or logic analyzer to verify if data is actually coming out or not - if you don't KNOW, for sure, that the Arduino code is working.

    /Henrik.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: PIC18F I2C Communication with Arduino

    I've literally never used I2CWrite.
    Really Henrick? Wow, I use it all the time to write to serial eeprom's, a/d's and i/o expanders, etc. You should really design more hardware..
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: PIC18F I2C Communication with Arduino

    Can you inform us which 18F pic you are using?

    Most of the 18F PICs (28 pin and 40 pin) have the hardware I2C pins on PORT C not PORTB. Whilst I'm sure PBP can define any pins, it might be "better" to use the actual pins associated with the hardware module on the PIC, eg

    Code:
    SCLpin             var PORTC.3          'clk
    SDApin             var PORTC.4          'data

  4. #4
    Join Date
    May 2016
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: PIC18F I2C Communication with Arduino

    I am using PIC18F2450 which doesn't have hardware I2C pins.Isn't I2CWRITE just a software solution and not using actual hardware?

    here is arduino code:

    Code:
    #include <Wire.h>
    
    void setup() {
      Wire.begin(0x26);                // join i2c bus with address
      Wire.onReceive(receiveEvent); 
      Serial.begin(9600);          
      
    }
    
    void loop() {
     delay(1000);
    
    }
    
    
    void receiveEvent(int howMany) {
    
      while (1 < Wire.available()) { 
        char c = Wire.read(); 
        Serial.print(c);    
      }
      int x = Wire.read();   
      Serial.println(x);
    }

  5. #5
    Join Date
    May 2016
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: PIC18F I2C Communication with Arduino

    I am using 2 2.2K pull up resistors on pins.

    Correct arduino code:

    Code:
    #include <Wire.h>
    
    void setup() {
      Wire.begin(0x26);                // join i2c bus with address
      Wire.onReceive(receiveEvent); 
      Serial.begin(9600);          
      
    }
    
    void loop() {
     delay(1000);
    
    }
    void receiveEvent(int howMany) {
    
    while(Wire.available() > 0){  
      int x = Wire.read();    
     Serial.println(x); 
      }
    }

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: PIC18F I2C Communication with Arduino

    Dave,
    I do design hardware from time to time but yeah, I'd love to do more. I tend to use SPI as I think it's both easier and faster and all the functions you mention are available in chips with SPI-interface as well as I2C so I've never actually had the need TO use it - that's it really.

    Scampy,
    I2C/Read/Write are not "hardware assisted" commands, they do not use the (M)SSP module in the PIC so any pins can be used.

    picmilan,
    I'll repeat what I said earlier: Check if the pins you're using has analog functions and make sure they're turned off.

    /Henrik.

  7. #7
    Join Date
    May 2016
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: PIC18F I2C Communication with Arduino

    Quote Originally Posted by HenrikOlsson View Post
    picmilan,
    I'll repeat what I said earlier: Check if the pins you're using has analog functions and make sure they're turned off.

    /Henrik.
    Yeah,You are right! Looking at datasheet those pins are analog by default..

    Now Control Address and write address is what confuses me.Control Address is 0x26 as defined in arduino code,right? so what is write address?

    Is SPI easier? I don't have many pins available but if I2C doesn't work I guess I don't have any other option.

Similar Threads

  1. Interfacing with Arduino I2C LCD
    By norohs in forum Documentation
    Replies: 47
    Last Post: - 30th May 2017, 18:53
  2. I2C lcd ( arduino ) with PICBASIC, help
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 92
    Last Post: - 10th September 2014, 18:00
  3. EEprom and MCP9801 I2C communication problems
    By aajgss in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 3rd September 2011, 21:45
  4. How do I operate an Arduino I2C LCD
    By menta in forum General
    Replies: 8
    Last Post: - 13th July 2011, 02:28
  5. Replies: 2
    Last Post: - 10th June 2005, 02:34

Members who have read this thread : 0

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