This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SCI port and I2C interface initialization for TMS570LS3137PGE

Other Parts Discussed in Thread: TMS570LS3137

Hi Zhaohong,

Wish you had a good holiday!

Back to my project I asked help earlier. After a few days efforts, I still did not solve my problems.

I tried the suggestions and saw some example codes. I did not see any issue in my codes, but the problems still there.

(1) for the SCI port.  The receiving does not work. Transmitting works well. I tried LIN mode, it showed same thing.

I'd like you to help explain the bit-2 of the SCI flag register, it says "IDLE".

In my case, in SCI mode, as long as set and enable peripheral power as below

  /** - Enable Peripherals */   CLKCNTRL_bit.PENA = 1U;

The SCI flag register bit2 was set as "1". and never changed no matter whatever tried.

Base on the ref manual (page 1413), IDLE='1' means "the idle period has not been detected, the SCI will not receive any data".

It also mentioned one of below events occur can make SCI enters the idle state - (1) system reset, (2) power down, (3)SCI software reset, (4) RX pin is configured as GP I/O pin.

But - I tried (3) and (4), they can not clear the "IDLE" status.

* However, if I set to LIN mode, this bit was cleared.  But I still can not receive data so far.

 

(2) the I2C module, I still can not access the I2C registers. As suggested, using disassembly step by step, I can see the register address is the one listed in datasheet.

the base address is 0XFFF7D400

 

I possible, I'd like to talk to you for details. My #713-272-4503.

Thanks,

Yanzhong

  • Yanzhong,

    On SCI bus, you need to make sure that the data pins are in "high" state when there is active transfer. Would you please try the internal loopback mode to see if your software works?

    I am not sure why you cannot access the registers. Can you send the complete project over for us to take a look?

    Thanks and regards,

    Zhaohong

  • Zhaohong,

    I did try loop-back mode for the SCI. It did not work either.

    I just double check the RX pin status during the data transmit and idle. It is High (pull-up enabled, otherwise it about 1.8V)

    I am using IAR Embedded Workbench. So far, I just based on their "getting started" project and adding my portion.

    There are 3 files: tms570ls3137_cstartup.s, low_level_init.C, main.C  (I did not touch the .s file)

    I insert the files and IAR header file for TMS570LS3137PEG.

    Yanzhong3201.570LS3137PGE_ThermoFisher.zip

    Thanks,

    Yanzhong

  • Yanzhong,

    SCI TX should drive close to 3.3V when it is not transmitting. You may want to use a scope to see if it is changing over time.

    It seems that the source code is constructed differently compared to TI compiler. I have two observations from the source code you sent.

    (1) I did not not find a code section with initialize global variables. You may not use globals at all or they do not need to have initial values.

    (2) For instructions as "CLKCNTRL_bit.PENA = 1U;", I am not sure how this data struct is defined to the correct address.

    I would suggest the following.

    (1) After running initialization, can you check if the system registers got the expected value using the memory display from the debugger? If the values are not correct, can you start initialization and check the register values after each write? If they are not correct, can you check the assembly instructions in the disassembly window and related CPU registers to see if the operation is correct?

    (2) Do the same thing for SCI/LIN and I2C.

    I would recommend replacing the instruction at address 0x0 with instruction "b #-8". This instruction holds CPU to address 0x0 after reset. When you connect debugger to CPU, you will see everything at default condition. This will make your debug session repeatable.

    Thanks and regards,

    Zhaohong

  • Zhaohong,

    Thanks for the suggestion. I will look into it.

    It's confused when comparing the codes in two different system.

    I've sent the same files to IAR to see if they can catch something. will update you later.

    Regards,

    Yanzhong

     

  • Hi Zhaohong,

     

    I finally figured out my problems.

    For SCI port, the receiving actually was working, but cannot see the data in receiving regisiter in debug mode of IAR tool.

    For I2C port, I think it's a bug of IAR tool. The defined I2C control registers as 16-bit registers.

    Accoding to MCU ref manual, the I2C registers should be 32-bit registers with up 16-bit to be '0'.  (The manual is a little bit confusion there)

    Thank you for your support anyway!

    (sorry, I didn't know how to close the earier threads.)

    Yanzhong

     

     

     

  • Hi Zhaohong,

    I still need your help to take a look at my I2C initialization. - I still don't make it work yet.

    Now, using 32bit register access, I can set the I2C registers. But I can not send data out - SCL pin does not have clock either.

     

    (1) When MDR.STT (start condition) was set as '1', both SDA and SCL pins generated a "LOW" pulse.  (the 2 pins were pull-up to HIGH normally)

    Below status flag bits were set to '1'

    AL (bit0) = 1  (lost an arbitration ?)

    TXRDY (bit4) = 1  (I2CDXR is empty)

    XSMT (bit10) =1   (Transmit shift empty, no underflow has occurred)

    BB (bit12) = 1 (the bus is busy)

    (2) if I continued to write data to I2CDXR,  I can see I2CDXR has the data, but I can not see signals out at the SCL and SDA pins.

    at the same time, TXRDY (bit4) changed to be '0'. But the rest AL, XSMT, BB still remained '1'.

     

    My system has VCLK=59.904MHz.   I set Prescale =7   So, the module clock is 59.904/(7+1)=7.488MHz.

    Then I set I2CCKL= 22, and I2CCLH=43, then I get the baud rate about 100K.

     

    Below is my initialization code

      I2CMDR_bit.nIRS = 0;         

     I2CPSC = 0x00000007U; // set prescaler = 7   

     I2CCKL = 0x00000016U; // PLL option-1: 0x2D (45); PLL option-2: 0x16 (22)  

     I2CCKH = 0x0000002BU; // PLL option-1: 0x2C (44); PLL option-2: 0x2B (43)

      I2COAR = 0x0000007FU;  // Own Adder, bit-0 to bit6  

      I2CIMR = 0x00000000U;  // Interruption Mask Register ("1" = enable) - disable all interruptions  

      I2CSAR = 0x0000000EU; // Slave address: DAC (0x0E), I/O Exp1 (0x20), I/O Exp2 (0x24)     

     I2CPFNC = 0x00000000U;  // Use I2C function on SDA and SCL  

    I2CPDR = 0x00000000U;   // enabled open-drain

    I2CPDIS = 0x00000000U; // SDA and SCL pull function enabled  

     I2CPSEL = 0x00000003U; // SDA and SCL pull-up selected

     I2CMDR_bit.nIRS = 1;        // out of reset

        I2CMDR_bit.STB = 1;    //start byte enabled

        I2CMDR_bit.MST =1;     //master mode

        I2CMDR_bit.TRX = 1;     //transmit

       I2CMDR_bit.RM = 1;     // repeat mode

      I2CMDR_bit.STT = 1;     // set start condition - which generated "LOW" pulse on SDA and SCL pins. 

     I2CDXR = 0x00000055U;  // send data out

     

    I had your sample code for I2C initialization, I did not see much different.

    See if you can catch any thing or advice.

    Thanks,

    Yanzhong

     

     

     

  • Yanzhong,

    When an I2C master drives SCL pin high, it is in open drain mode. You need to have a strong pull up resistor on SCL. Same thing is required for SDA. When it is connected to a slave, the slave can halt communication when it is no ready by holding SCL low. The communication will also be halted if the master does not see the acknowledgement signal from the slave.

    You need first check if the pinmux is set correctly for I2C. You may need to check the values in the pinmux register to make sure if they are correct. You can set I2C pin in GIO mode and see if they can be toggled. Then make sure that if you have pull up resistors on the pins. If you do not connect a work slave, you can only see the signals when master send out the address.

    Thanks and regards,

    Zhaohong

  • Zhaohong,

     

    The I2C port works now after I added external pull-up resistors for SDA and SCL - I thought the internal pull-up was enough to drive it.

    So far, I can see clock and data sent out at Master and Transmit mode. But it stuck and the BB (bus busy) =1 - I thought it was not response from Slave.

     

    I may still need some time to play around the hand shaking between the MCU and devices.

    I'd like you to provide some explain about these  I2CMDR control bits

    (1) STT (start condition) - as a Master and Transmit mode, it seems I have to set STT bit before sending a data byte.  Do I have to set STT=1 before each data byte send?

    (2) STP (stop condition) - when do I suppose to use or set this bit?

    (3) RM (repeat mode) - I set RM=1, but I can not send data continously.  (Does this because of the "BB=1"?)

    (4) STB (start byte mode) - when set STB=1, does every send always using "00000001" to replace the salve address in  I2CSAR unitl STB is cleared to "0"?

    (5) FREE (Free running bit) - what's the mean of "The I2C runs free" when set FREE = '1'.

     

    Thanks,

    Yanzhong

     

  • Yanzhong,

    (1) STT (start condition) - It needs to be set before sending a message. Not needed for subsequent data.

    (2) STP (stop condition) - It needs to be set after master completes sending/receiving a message.

    (3) RM (repeat mode) - when RM=1, you can keep sending data regardless of ICCNT value. When RM=0, a stop condition will be automatically generated after ICCNT bytes have been sent/received.

    (4) STB (start byte mode) - When STB=1, The slave address being sent is "00000001" instead the value in  I2CSAR. You need to check I2C protocol spec to see when it is needed.

    (5) FREE (Free running bit) - In the free running mode (FREE = '1'), I2C will not be halted when SCL is low. It is only used for IP debugging. The FREE bit should always be set to zero for normal use.

    Please select the 'verify" button if you get the information you need.

    Thanks and regards,

    Zhaohong

  • Zhaohong,

    I just found that the address was sent out is from I2COAR, not from I2CSAR.

    As I learnt, when FDF = 0, the Master transmit data with slave address which should be from I2CSAR.

    I appreciate your help.  As I move forward, may bother you again. 

    Yanzhong