Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 1 of 1

Thread: TCA 8418 sending NACK after pressing a button, I2C problem

  1. #1

    TCA 8418 sending NACK after pressing a button, I2C problem

    So, I am trying to make a keypad. I have managed to set sīthe chip up, but whenever I press a button and then try to read which button was pressed I recieve NACK on adress.
    Code:
    #include <Wire.h>
    
    #include <WireKinetis.h>
    
    #include "Wire.h"
    
    #define adress 0x34
    
    void setup() {
    pinMode(11, INPUT_PULLUP);
    pinMode(13, OUTPUT);
      Serial.begin(9600);
      delay(1000);
      Serial.println("setup begin");
      Wire.begin();
      
      Wire.beginTransmission(0x34);
                Serial.println("setup");
      Wire.write(0x01);
                 Serial.println("setup");
      Wire.write(0xff);   //initial setup of the chip
                Serial.println("setup");
    int n = Wire.endTransmission();
    
    Serial.println(n);
    
    Serial.println("setup");
    
       Wire.beginTransmission(adress);
       Wire.write(0x1D);    
       Wire.write(0xF); // set row 1-4
      n = Wire.endTransmission();
      Serial.println(n);
    Serial.println("setup");
        Wire.beginTransmission(adress);
        Wire.write(0x1E);
        Wire.write(0xF); //set colum 1-4
        n = Wire.endTransmission();
         Serial.println("setup done");
        Serial.println(n);
    }
    byte REG;
    void loop() {
    
      int INTERUPPT = digitalRead(11);
      if(INTERUPPT == LOW)
      {
         digitalWrite(13, HIGH);
      }
      
      delay(1000);
      
      
        Wire.beginTransmission(0x34);
        Wire.write(0x03);
        Serial.print("prenos: ");
       int m = Wire.endTransmission();
       Serial.println(m);
        Wire.requestFrom(0x34, 1);        // request 1 byte(s) from slave device.  
        while(Wire.available())             // slave may send less than requested.  
         {
          
          
          REG = Wire.read();  
          Serial.print("reg: ");
          Serial.println(REG);
          
         }
      
     // delay(1000);
    
    
    }
    Last edited by defragster; 07-14-2019 at 09:51 AM. Reason: removed dupe code block inset

Tags for this Thread

Posting Permissions

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