This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

simple I2C question TC74

I have a TC74 temp sensor

https://www.microchip.com/wwwproducts/en/TC74

and want the temperature 

using code below I always get a greenlight / EVENTS ERROR

thank you in advance for any all help

int main(void)
{
short temperature = 0;

nrf_gpio_cfg_output(42); //output that needs to be off to power MEMs
nrf_gpio_cfg_output(46); //RED
nrf_gpio_cfg_output(47); //GREEN
nrf_gpio_pin_clear(42);
nrf_gpio_pin_set(46);//turns off LED
nrf_gpio_pin_set(47);//turns off LED

NRF_TWIM0->ENABLE=0;//disable nordic as master
NRF_TWIM0->PSEL.SCL=11;//P0.11
NRF_TWIM0->PSEL.SDA=13;//P0.13
NRF_TWIM0->FREQUENCY=0x01980000;//100kHz
NRF_TWIM0->ADDRESS=(0b11001000); // 1001 000--> x100 100 | x 1 fpr read 0 for write
NRF_TWIM0->RXD.PTR = temperature; //store 1 byte temperature in temperature variable
NRF_TWIM0->SHORTS = 0;
NRF_TWI0->INTENSET = 0x061C0202; // set interupts
NRF_TWIM0->ENABLE=6;//enable nordic as master
NRF_TWI0->TASKS_STARTRX = 1;
while (1)
{
if(NRF_TWI0->EVENTS_STOPPED) nrf_gpio_pin_clear(46);
if(NRF_TWI0->EVENTS_ERROR) nrf_gpio_pin_clear(47);//Always comes up with an error
}
}

  • my mistake, the temperature register is 00

    and dont call me Shirley

  • I fixed it. thank you


    //need to declare in global fashion suggest putting in main.c file at top just after includes
    uint8_t temp_buffer[] = {0x01,0x00,0x00}; //used to READ temperature | STARTRX = 1 | stored in temp_buffer[0]

    /**
    * @brief Function for initializing the TC74
    */
    void InitializeTC74_TemperatureSensor(void)
    {
    nrf_gpio_cfg_output(42); //output that needs to be off to power MEMs | P1.10 | MEMS_PWR_CTRL
    nrf_gpio_pin_clear(42); //PNP transistor so output low to power upp <see print 32341748>
    nrf_delay_ms(500); //give sensor time to power up

    uint8_t rx_buffer[]={0x00,0x00}; //used in STARTTX

    NRF_TWIM0->ENABLE=0;//disable nordic as master to configure
    NRF_TWIM0->PSEL.SCL=11;//P0.11
    NRF_TWIM0->PSEL.SDA=13;//P0.13
    NRF_TWIM0->FREQUENCY=0x01980000;//100kHz
    NRF_TWIM0->ADDRESS=(0x48); // 1001 000--> x100 100 | x 1 fpr read 0 for write |NORDIC takes care of the read/write bit
    NRF_TWIM0->RXD.PTR=temp_buffer;
    NRF_TWIM0->RXD.MAXCNT=2; // size of temp_buffer
    NRF_TWIM0->TXD.PTR=rx_buffer;
    NRF_TWIM0->TXD.MAXCNT=1;//size of rx_buffer
    NRF_TWIM0->SHORTS = 0;//disable shortcuts
    NRF_TWIM0->ENABLE=6;//enable nordic as master

    //initialze TC74 to take data | normal mode
    NRF_TWIM0->EVENTS_ERROR=0;
    NRF_TWIM0->ERRORSRC=0;
    NRF_TWIM0->EVENTS_STOPPED=0;
    NRF_TWI0->EVENTS_RXDREADY=0;
    NRF_TWIM0->TASKS_STARTTX = 1;
    while(NRF_TWI0->EVENTS_TXDSENT==0){}
    NRF_TWIM0->TASKS_STOP=1;
    NRF_TWI0->EVENTS_TXDSENT=0;
    nrf_delay_ms(100);

    }

    /**
    * @brief Function that returns temperature in degrees Celcius when called */
    uint8_t GetTemperature(void)
    {
    NRF_TWIM0->TASKS_STARTTX = 0;
    NRF_TWI0->EVENTS_RXDREADY=0;
    NRF_TWIM0->TASKS_STARTRX = 1;
    while(NRF_TWI0->EVENTS_RXDREADY==0){}
    NRF_TWIM0->TASKS_STOP=1;
    NRF_TWI0->EVENTS_RXDREADY=0;
    return temp_buffer[0];
    }

Related