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

Thread: Teensy 4.0 How to write to LPI2C registers?

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Posts
    2

    Teensy 4.0 How to write to LPI2C registers?

    Hello,

    Could you help me if you have a solution?
    My problem is that I cannot write values to LPI2C registers.

    1. I can read LPI2C1_VERID and LPI2C1_PARAM.
    2. I tried to write 0x00000001 to LPI2C1_MCR, however, it stayed 0x00000000.
    3. Also, I couldn't write value to LPI2C1_ MIER, LPI2C1_MCFGRx or others.

    I tried it by the following sketch,

    Code:
    int cntDAT;
    byte inDAT[63];
    uint32_t uintTMP;
    
    IMXRT_LPI2C_t *port_i2c;
    
    void setup() {
      port_i2c = &IMXRT_LPI2C1;
    }
    
    void loop() {
      cntDAT = 0;
    
      while(Serial.available()){
        delay(5);
    
        inDAT[cntDAT] = Serial.read();
        cntDAT = cntDAT + 1;
      }
    
      if(cntDAT > 0){
        uintTMP = port_i2c->VERID;
        Serial.print(uintTMP);
        Serial.print("-");
        uintTMP = port_i2c->PARAM;
        Serial.print(uintTMP);
        Serial.print("-");
        uintTMP = port_i2c->MCR;
        Serial.print(uintTMP);
        Serial.print("-");
        uintTMP = port_i2c->MIER;
        Serial.print(uintTMP);
        Serial.print("--");
    
        port_i2c->MCR = 0x00000001;
        port_i2c->MIER = 0x00007F03;
        Serial.print("-");
        
        uintTMP = port_i2c->VERID;
        Serial.print(uintTMP);
        Serial.print("-");
        uintTMP = port_i2c->PARAM;
        Serial.print(uintTMP);
        Serial.print("-");
        uintTMP = port_i2c->MCR;
        Serial.print(uintTMP);
        Serial.print("-");
        uintTMP = port_i2c->MIER;
        Serial.print(uintTMP);    
      }
    }
    and got the following output from the serial monitor.

    16842755-514-0-0---16842755-514-0-0

    16842755 = 0x1010003 means VERID.
    514 = 0x00000202 means PARAM.
    This code tried to update MCR from 0 to 1 and MIER from 0 to 32515 = 0x00007F03, however, it failed.

    I have tried that I can write values to GPIO registers with a similar code.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,462
    Not seen this come up before - but did find this app note for a different freescale/NXP processor : nxp.com/docs/en/application-note/AN5245.pdf

    If the 1062 can support it as desired those notes may help - or suggest a way to a solution - that 'AN.pdf' seems to rely on an DEV kit SDK example - perhaps there is something like that for the 1062 - or an app note or other item beyond the RefMan or other doc linked on the product page.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,470
    In many cases like this, it is often easiest to look at code that ships with the Teensyduino release, at least to get ideas, even if you may be the type who who wants to write everything from scratch.

    In this case the Wire library.

    My guess is that you have not enabled the LPI2C1 clock register and many IMXRT subsystems will not work without first enable access. In many cases it will cause your program to fault...

    SO for this one I would expect to see something like:
    Code:
    CCM_CCGR2 |= CCM_CCGR2_LPI2C1(CCM_CCGR_ON);
    Before you start to try to access those registers.

    Hope that helps

  4. #4
    Junior Member
    Join Date
    Jan 2021
    Posts
    2
    Hello @defragster, @KurtE

    Thank you for the reply.
    My problem has been solved by enabling the clock.

    Also, I understand I can study from AN or Teensyduino library. Thank you for the advice.

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,462
    Good luck, if you get a working example posting it may help others and show how to use this feature.

    Had hope that AN would show the 'enable' KurtE mentions, even if for wrong processor - if it does it is not as Clear as Kurt made it

    But post #1 made it seem the code ran and did not Fault so wrongly assumed and skipped noting that

Posting Permissions

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