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

Parents
  • From what I can see (red light 'pin' 46) i am getting an overrun error.  I dont know how to fix or diagnose this though

  • i got the error to go away using

    NRF_TWI0->TASKS_STARTRX = 1;
    while(NRF_TWI0->EVENTS_RXDREADY==0){}
    NRF_TWI0->TASKS_STOP=1;
    NRF_TWI0->EVENTS_RXDREADY=0;
    temperature = NRF_TWI0->RXD;

    but my temperature is zero. i must be receiving the temperature wrong.

Reply
  • i got the error to go away using

    NRF_TWI0->TASKS_STARTRX = 1;
    while(NRF_TWI0->EVENTS_RXDREADY==0){}
    NRF_TWI0->TASKS_STOP=1;
    NRF_TWI0->EVENTS_RXDREADY=0;
    temperature = NRF_TWI0->RXD;

    but my temperature is zero. i must be receiving the temperature wrong.

Children
  • can you provide example of how to properly get /access the byte read?

  • Have you looked at the TWI examples in the SDK?

  • 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.