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.

USING I2C2 WITH TI-RTOS

Hi, I'm using TIVA C Connected launchpad with TI-RTOS V2.00.02... and CCs v6.

I am using interface I2C0 for communicate with RTC DS1307 and SSI2 to connect my SD Card.

I can not communicate anything in I2C2 interface (PN4 and PN5). Measuring with an oscilloscope, I found that always stays at 0 volts, unlike I2C0 (PB2 and PB3).

What can I do to solve this?
  • Hi Tiago Possato,

    Were you able to successfully run the I2C example?

    Steve

  • Hi Esteve, I do not have BoosterPack (TMP006 or another), but managed to communicate with a DS1307, on the I2C0, see the function:

    =================================

    /*
     * rtc.c
     * Primeira versao da biblioteca para acessar o modulo de tempo real DS1307
     *
     *  Created on: 18/08/2014
     *      Author: Tiago
     */
    #include "rtc.h"
    
    // convert BCD para decimal
    unsigned char bcd2dec(unsigned char val) {
    	return ((val / 0x10 * 0xA) + (val % 0x10));
    }
    
    /**
     * Le os valores do RTC e escreve na memoria apontada por *read
     */
    Void lerRTC(char *read) {
    
    #define READ_COUNT 7
    	UInt peripheralNum = 0; /* Interface I2C0 */
    	I2C_Handle i2c;
    	I2C_Params i2cParams;
    	I2C_Transaction i2cTransaction;
    	UChar writeBuffer[9];
    	writeBuffer[0] = 0;
    	UChar readBuffer[READ_COUNT];
    	Bool transferOK;
    	I2C_Params_init(&i2cParams);
    	i2c = I2C_open(peripheralNum, &i2cParams);
    	if (i2c == NULL) {
    		printf("Nao foi possivel abrir a interface I2C0!\n");
    		fflush(stdout);
    		return;
    	}
    
    	//Seta os parametros para a comunicacao
    	i2cTransaction.slaveAddress = 0x68; /* 7-bit peripheral slave address */
    	i2cTransaction.writeBuf = writeBuffer; /* Buffer to be written */
    	i2cTransaction.writeCount = 1; /* Number of bytes to be written */
    	i2cTransaction.readBuf = readBuffer; /* Buffer to be read */
    	i2cTransaction.readCount = READ_COUNT; /* Number of bytes to be read */
    
    	//Comunica com o dispositivo
    	transferOK = I2C_transfer(i2c, &i2cTransaction);
    	if (!transferOK) {
    		printf("Falha na comunicacao\n\tDispositivo externo nao encontrado!\n");
    		fflush(stdout);
    		I2C_close(i2c);
    		return;
    	}
    
    	//converte os valores lidos e escreve na memoria do microcontrolador
    	*(read) = bcd2dec(readBuffer[3]); //dia da semana
    	*(read + 1) = bcd2dec(readBuffer[4]); //dia
    	*(read + 2) = bcd2dec(readBuffer[5]); //mes
    	*(read + 3) = bcd2dec(readBuffer[6]); //ano
    	*(read + 4) = bcd2dec(readBuffer[2]) & 0x3f; //hora
    	*(read + 5) = bcd2dec(readBuffer[1]); //minuto
    	*(read + 6) = bcd2dec(readBuffer[0]) & 0x7f; //segundo
    
    	I2C_close(i2c);
    }

    =========================

    If I try change peripheralNum for "1" or
    "i2c = I2C_open(Board_I2C3, &i2cParams); ", "Board_I2C3" is defined on "board.h", dont works.

    I thought there's something wrong in the function "Board_initI2C ();" but I found nothing.
    In line 95 of the file "EK_TM4C1294XL.h" is written "EEK_TM4C1294XL_I2CName" is right with two "E"?

  • Thanks for posting your code.

    It looks like you may be missing the call to I2C_init(), can you please try calling that?

    Tiago Possato said:
    In line 95 of the file "EK_TM4C1294XL.h" is written "EEK_TM4C1294XL_I2CName" is right with two "E"?

    This is a typo.  I checked the latest version of the code and it has been fixed (will be available in the next TIRTOS release).

    Steve

  • Oh sorry, I already do this in the "main.c":

    int main(void) {
    	Board_initGeneral();
    	Board_initGPIO();
    	Board_initI2C();
    	Board_initSDSPI();
    	Board_initUART();
    
    	GPIO_write(Board_LED0, Board_LED_OFF);
    	GPIO_write(Board_LED1, Board_LED_OFF);
    	GPIO_write(Board_LED2, Board_LED_OFF);
    
    	add_device("UART", _MSA, UARTUtils_deviceopen, UARTUtils_deviceclose,
    			UARTUtils_deviceread, UARTUtils_devicewrite, UARTUtils_devicelseek,
    			UARTUtils_deviceunlink, UARTUtils_devicerename);
    
    	freopen("UART:0", "w", stdout);
    	setvbuf(stdout, NULL, _IOLBF, 128);
    
    	freopen("UART:0", "r", stdin);
    	setvbuf(stdin, NULL, _IOLBF, 128);
    
    	UARTUtils_systemInit(0);
    
    	System_printf("Starting the example\nSystem provider is set to SysMin. "
    			"Halt the target to view any SysMin contents in ROV.\n");
    
    	System_flush();
    
    	BIOS_start();
    
    	return (0);
    }

    and when I need to read data, I call the function:

    lerRTC(char *read)

    Tiago

  • Hi Tiago,

    this might be a silly question...but do you have pullup resistors on your I2C3 SDA and SCL lines?

  • Hi Tom,

    This isn't a silly question, I'm a new I2C network developer. It was only that. I forgot the hardware!

    Thanks for help, Tom and Steven.

    Tiago Possato