Jump to content
Sign in to follow this  
L.R.A

TM4C129 I2C not working

Recommended Posts

So i decided to use a code that i used in the stelaris launchpad to control a srf08 with the new tm4c129 launchpad

 

I changed the ports and i2c_bases acordingly but it doesn't work.

Everytime i try to send anytigh i just sse in the osciloscope the pull-ups

 

Is there any change in the new microcontroler that i'm missing and i'm not aware of?

 

 

here is the code for the I2C0_BASE just to send data


#define PART_TM4C1294NCPDT
#include <inttypes.h>
#include "inc/hw_i2c.h"
#include "driverlib/pin_map.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"


uint32_t ulI2CBase =I2C0_BASE;

void setup()
{
  
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

  GPIOPinConfigure(GPIO_PB2_I2C0SCL);
  GPIOPinConfigure(GPIO_PB3_I2C0SDA);

  GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);	//	special I2CSCL treatment for M4F devices
  GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);	
 I2CMasterInitExpClk(I2C0_BASE, 120000000, false); 
  SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
  //ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);

  
  //while(1);
  Serial.begin(9600);
}

void loop()
{
  i2cEnvia(0x71, 0x00, 0x51);
  delay(70);
  // put your main code here, to run repeatedly:

}
int i2cEnvia(unsigned char ucSlaveAdress,unsigned char ucReg, unsigned char ucValue){
  //
  // Check the arguments.

  //
  // Wait until master module is done transferring.
  //
  while( I2CMasterBusy(ulI2CBase))
  {
    Serial.println("busy1");
  };
   Serial.println("notbusy1");
  //
  // Tell the master module what address it will place on the bus when
  // writing to the slave.
  //
  I2CMasterSlaveAddrSet(ulI2CBase, ucSlaveAdress, 0);

  //
  // Place the command to be sent in the data register.
  //
  I2CMasterDataPut(ulI2CBase, ucReg);

  //
  // Initiate send of data from the master.
  //
  I2CMasterControl(ulI2CBase, I2C_MASTER_CMD_BURST_SEND_START);

  //
  // Wait until master module is done transferring.
  //
  while( I2CMasterBusy(ulI2CBase))
  {
     Serial.println("busy2");
  };

  //
  // Check for errors.
  //
  if( I2CMasterErr(ulI2CBase) != I2C_MASTER_ERR_NONE)
  {
     Serial.println("erro1");
    return 0;
  }

  //
  // Place the value to be sent in the data register.
  //
  I2CMasterDataPut(ulI2CBase, ucValue);

  //
  // Initiate send of data from the master.
  //
  I2CMasterControl(ulI2CBase, I2C_MASTER_CMD_BURST_SEND_CONT);

  //
  // Wait until master module is done transferring.
  //
  while( I2CMasterBusy(ulI2CBase))
  {
     Serial.println("busy3");
  };

  //
  // Check for errors.
  //
  if( I2CMasterErr(ulI2CBase) != I2C_MASTER_ERR_NONE)
  {
      Serial.println("erro2");
    return 0;
  }

  //
  // Initiate send of data from the master.
  //
  I2CMasterControl(ulI2CBase, I2C_MASTER_CMD_BURST_SEND_FINISH);

  //
  // Wait until master module is done transferring.
  //
  while( I2CMasterBusy(ulI2CBase))
  {
     Serial.println("busy4");
  };

  //
  // Check for errors.
  //
  if( I2CMasterErr(ulI2CBase) != I2C_MASTER_ERR_NONE)
  {
      Serial.println("erro3");
    return 0;
  }

  //
  // Return 1 if there is no error.
  //
    Serial.println("done");
  return 1;
}


Share this post


Link to post
Share on other sites

Hi,

I just don't know so I just ask - did you noticed the change of system control clock function in TM4C129x micros? this gave a lot of pain to many users so my question. This should be left outside so the users can change/check. 

L

 

NB: Looks like this:

    //
    // Run from the PLL at 120 MHz.
    //
    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                             SYSCTL_OSC_MAIN |
                                             SYSCTL_USE_PLL |
                                             SYSCTL_CFG_VCO_480), 120000000);

and the return value is the system clock or 0 if failed.

Share this post


Link to post
Share on other sites

Yes i did noticed that the fuction to set freq is diferent and that SysCtlClockGet() doesn't work.

 

i'm using energia so i didn't even set the frequency

Share this post


Link to post
Share on other sites

@L.R.A

 

Have you tried with Energia?

 

Have you considered the Creating IoT Solutions with the TM4C1294XL Connected LaunchPad Workshop and especially chapter 7 about I²C?

 

I tried with the module 0, 1, 2 and 3 with energia. (used setModule fuction) and notigh.

Today gona try to check the energia files. 

 

That's seems to be a very nice workshop, gona try it 

Thanks!

Share this post


Link to post
Share on other sites

Well after some issues (uControler geting locked and such) i did some testing and Wire library works fine (altough i still can't get it working at 100% with srf08)

 

I think the same API i use for the tm4c123 doesn't work with tm4c129 because there's some new features like FIFO and and uDMA.

I'll try doing some more reading and figured it out, maybe even use the FIFO

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×