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
}
}

  • i shouldve been more specific, i meant an example of just how to get the read byte in my code. 

    the manual says it is in pointer and to assign a location to pointer so i set NRF_TWIM0->RXD.PTR = temperature which i made a short since it is only 1 byte of data but temperature is always zero and my sensor is at room temperature so it should be a nonzero number. 

  • ok, still shooting in the dark here.

    I noticed that there are 2 registers, a configuration (read/write, register 01) and a temperature (read only, register 01).

    I added a write portion where the TXD pointer is pointing to a 2 component array (configuration register, value of zero).  the TC74 wants to see its address with the write bit, then the register writing to and then the value.  The nordic outputs the address, write bit, and then the pointer data so this seems compatible.

    TC74 wants to see address with read bit, register to read, repeat of address, then gives the data (figure 3-1 of datasheet <link in original post>). So i have the RX pointer to a 3 element array (configuration register, TC74 address, and zero that should hopefully get filled with the value of the configuration register - 6th bit should indicate data ready 4-8 times per second)      Figure 90 of the nrf52840 doesnt seem to agree with this scheme. and subsequently I never get notification that data is ready.

    any help or ideas to try would be greatly appreciated.

       nrf_delay_ms(250);
        uint8_t transmit_buffer[2] = {0x01,0b00000000};//send 0 to configuration register 0x01 to enable normal mode (7th bit) and reset data ready (6th bit)
        uint8_t receive_buffer[3] = {0x01,0b1001000,0};//read from 0x01, repeat address (without read/write bit) due to change in dataflow direction, zero out data byte
    
        nrf_gpio_cfg_output(42); //output that needs to be off to power MEMs
        nrf_gpio_pin_clear(42);
        nrf_delay_ms(500); //give sensor time to power up
    
        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=(0b1001000); // 1001 000--> x100 100 | x 1 fpr read 0 for write
        NRF_TWIM0->RXD.PTR=receive_buffer;
        NRF_TWIM0->RXD.MAXCNT=12;//only receive 1 byte but put at 12 just incase
        NRF_TWIM0->TXD.PTR=transmit_buffer;
        NRF_TWIM0->TXD.MAXCNT=8;
        NRF_TWIM0->SHORTS = 0;
        NRF_TWIM0->ENABLE=6;//enable nordic as master
        
        NRF_TWI0->EVENTS_ERROR=0;
        NRF_TWIM0->ERRORSRC=0;    
        NRF_TWI0->EVENTS_STOPPED=0;
        nrf_delay_ms(250);
        NRF_TWI0->EVENTS_RXDREADY=0;
        NRF_TWI0->TASKS_STARTTX = 1;
        while(NRF_TWI0->EVENTS_TXDSENT==0){}  
        NRF_TWI0->TASKS_STOP=1;
        NRF_TWI0->EVENTS_TXDSENT=0;
        nrf_delay_ms(500);
        
    
        NRF_TWI0->EVENTS_ERROR=0;
        NRF_TWIM0->ERRORSRC=0;    
        NRF_TWI0->EVENTS_STOPPED=0;
        nrf_delay_ms(250);
    
      while(receive_buffer[2]==0) //waiting for data ready bit to be set (should happen 4 to 8 times a second)
      {
        NRF_TWI0->EVENTS_RXDREADY=0;
        NRF_TWI0->TASKS_STARTRX = 1;
        while(NRF_TWI0->EVENTS_RXDREADY==0){}  
        NRF_TWI0->TASKS_STOP=1;
        NRF_TWI0->EVENTS_RXDREADY=0;
        nrf_delay_ms(50);
      }
        nrf_delay_ms(250);
        nrf_gpio_cfg_output(47); //GREEN
        nrf_gpio_pin_clear(47);

  • a configuration (read/write, register 01) and a temperature (read only, register 01)

    Surely, they can't both be 01 ?

Related