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.

Problem RTC ds1307

Other Parts Discussed in Thread: SYSBIOS

I am using interface I2C0 for communicate with RTC DS1307.

I'm having trouble with I2C_transfer().
When you call the function aprenta one stackoverflow problem in HWI.
The code is presented below.

s

Void TaskRTC() {

    UInt peripheralNum = 0; 
    I2C_Handle i2c;
    I2C_Params i2cParams;
    I2C_Transaction i2cTransaction;

    UChar writeBuffer[2];
    UChar readBuffer[8];

    Bool transferOK;

    I2C_Params_init(&i2cParams);
    i2c = I2C_open(0, &i2cParams);
    if (i2c == NULL) {
        system.abort("ERROR!!\n");
    }

    i2cTransaction.slaveAddress = 0x68; 

    // set second 
    writeBuffer[0]= 0x00;

    i2cTransaction.writeBuf = writeBuffer; 
    i2cTransaction.writeCount = 1; 
    i2cTransaction.readBuf = readBuffer; 
    i2cTransaction.readCount = 8; 

    //Comunica com o dispositivo
    transferOK = I2C_transfer(i2c, &i2cTransaction);
    if (!transferOK) {
        system.abort("ERROR!")    
        I2C_close(i2c);
        
    }
}


int main(void) {
    Board_initGeneral();
    Board_initGPIO();
    Board_initI2C();
  

    GPIO_write(Board_LED0, Board_LED_OFF);
       
    BIOS_start();

    return (0);
}
  • Hi Fabbrio,

    The HWI module uses the system stack which may be insufficient in your application. To increase the system stack, open the application's .cfg file and update "Program.stack" value.

    Vikram
  • Hi vikram

    I'm a new TI-RTOS developer how do i update the value program.stack?

      I did not find this parameter in application's.cfg.

    I2c_transfer when I run the program crashes and goes to idle_run loop and is calling Hwi_getStackInfo function.

  • Can you please share the application's cfg file?

    Vikram
  • /*
    * Copyright (c) 2015, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

    /*
    * ======== RTCTest.cfg ========
    */

    /* ================ General configuration ================ */
    var Defaults = xdc.useModule('xdc.runtime.Defaults');
    var Diags = xdc.useModule('xdc.runtime.Diags');
    var Error = xdc.useModule('xdc.runtime.Error');
    var Log = xdc.useModule('xdc.runtime.Log');
    var Main = xdc.useModule('xdc.runtime.Main');
    var Memory = xdc.useModule('xdc.runtime.Memory');
    var System = xdc.useModule('xdc.runtime.System');
    var Text = xdc.useModule('xdc.runtime.Text');

    var Task = xdc.useModule('ti.sysbios.knl.Task');
    var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');

    /*
    * Program.stack is ignored with IAR. Use the project options in
    * IAR Embedded Workbench to alter the system stack size.
    */
    if (!Program.build.target.$name.match(/iar/)) {
    /*
    * Reducing the system stack size (used by ISRs and Swis) to reduce
    * RAM usage.
    */
    Program.stack = 0x3000;
    }

    /*
    * Comment this line to allow module names to be loaded on the target.
    * The module name strings are placed in the .const section. Setting this
    * parameter to false will save space in the .const section. Error and
    * Assert messages will contain an "unknown module" prefix instead
    * of the actual module name.
    */
    Defaults.common$.namedModule = false;

    /*
    * Minimize exit handler array in System. The System module includes
    * an array of functions that are registered with System_atexit() to be
    * called by System_exit().
    */
    System.maxAtexitHandlers = 2;

    /*
    * Comment this line to allow Error, Assert, and Log strings to be
    * loaded on the target. These strings are placed in the .const section.
    * Setting this parameter to false will save space in the .const section.
    * Error, Assert and Log message will print raw ids and args instead of
    * a formatted message.
    */
    Text.isLoaded = false;

    /* ================ System configuration ================ */
    var SysMin = xdc.useModule('xdc.runtime.SysMin');
    System.SupportProxy = SysMin;
    SysMin.bufSize = 1024;
    /*
    * Uncomment this line to disable the output of characters by SysMin
    * when the program exits. SysMin writes characters to a circular buffer.
    * This buffer can be viewed using the SysMin Output view in ROV.
    SysMin.flushAtExit = false;
    */

    /* Enable Semihosting for GNU targets to print to CCS console */
    if (Program.build.target.$name.match(/gnu/)) {
    var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
    }

    /* ================ BIOS configuration ================ */
    /*
    * Disable unused BIOS features to minimize footprint.
    * This example uses Tasks but not Swis or Clocks.
    */
    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    BIOS.libType = BIOS.LibType_Custom;
    BIOS.logsEnabled = false;
    BIOS.assertsEnabled = false;

    BIOS.heapSize = 1024;

    /* Runtime stack checking is performed */
    Task.checkStackFlag = true;
    Hwi.checkStackFlag = true;

    /* Reduce the number of task priorities */
    Task.numPriorities = 4;

    /* ================ Task configuration ================ */
    var task0Params = new Task.Params();
    task0Params.instance.name = "taskRTC";
    task0Params.stackSize = 768;
    Program.global.task = Task.create("&echoFxn", task0Params);

    /* ================ Driver configuration ================ */
    var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS');
    TIRTOS.useGPIO = true;
    TIRTOS.useI2C = true;
    TIRTOS.useSPI = false;
    TIRTOS.useUART = true;
    Task.idleTaskStackSize = 4096;
    Task.defaultStackSize = 4096;
    BIOS.rtsGateType = BIOS.GateMutex;
  • Olá Fabrrio, vi sua mensagem, além do que o Vikram te falou, verifique se mais de uma task está chamando a mesma tarefa, cuide que você precisa fechar o I2C antes de abrir novamente, (I2C_close(i2c)), veja partes do meu código abaixo:

    No arquivo contendo o main:

    Alguns destes includes não são necessários para o I2C

    #include <xdc/std.h>
    #include <xdc/cfg/global.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/Memory.h>
    #include <xdc/runtime/System.h>

    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>

    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>


    #include "Board.h"

    int main(void) {
    Board_initGeneral();

    /* Habilita o periférico I2C0 */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    /* Configura os pinos para a utilizacao do I2C */
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    /* Inicializa o I2C2*/
    /* Habilita o periferico */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);

    /* Configura os pinos para a utilização do I2C */
    GPIOPinConfigure(GPIO_PN5_I2C2SCL);
    GPIOPinConfigure(GPIO_PN4_I2C2SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTN_BASE, GPIO_PIN_5);
    GPIOPinTypeI2C(GPIO_PORTN_BASE, GPIO_PIN_4);

    /* Inicializa os perifericos do I2C */
    Board_initI2C();

    ...
    }

    As funções para ler o RTC(São chamadas por uma task específica):

    // convert BCD para decimal
    unsigned char bcd2dec(unsigned char val) {
    return ((val / 0x10 * 0xA) + (val % 0x10));
    }

    Bool 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);
    I2C_close(i2c);
    return false;
    }

    //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) {
    I2C_close(i2c);
    return false;
    }

    //converte os valores lidos e escreve na memoria do microcontrolador
    read[0] = 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);
    return true;
    }



    No arquivo *.cfg

    TIRTOS.useI2C = true;
    Como comentado pelo Vikram:
    Program.stack = 2048;

    Se não funcionar, coloca o projeto no GitHub e manda o link, assim podemos ver o código num todo e ajudar melhor ;)

    Att:
    Tiago
  • The Program.stack is set to 0x3000 which is fine. BIOS.heapsize is set to 1024 which may be a problem. Let me check compare the configuration with the TI-RTOS example. Can you please tell me the device and version of TI-RTOS that you are using?