This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why doesn't the TWI transmit an address?

Using the nRF51422 with the TWI hardware version. Just playing around to verify signals with the following code which just configures the TWI1 and then repeats continuously with a master transmit of one data byte=0x57.

I get a 7 clock transitions on SCL along with the 0x57 on the SDA, but it never transmits the addresss. It seems once data is placed in the TXD, it automatically sends it out. I have tried reversing the start and TXD register steps as in the canned code and add a stop task but it is always the same, no address. What am I doing wrong?

thanks

/******************************************************************************************************************/
twi_master_config();
nrf_delay_ms(100);

NRF_TWI1->ADDRESS=0x78;

	while(1)  //endless single byte transmission
	{
		NRF_TWI1->TASKS_STARTTX=1;
		NRF_TWI1->TXD=0X57;
		nrf_delay_ms(10);
	}
	
	
void twi_master_config(void)
{
   NRF_TWI1->ENABLE=0;	//disable TWI
	
   NRF_GPIO->PIN_CNF[2] = 
        (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
      | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos)
      | (GPIO_PIN_CNF_PULL_Pullup    << GPIO_PIN_CNF_PULL_Pos)
      | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos)
      | (GPIO_PIN_CNF_DIR_Input      << GPIO_PIN_CNF_DIR_Pos);    

    NRF_GPIO->PIN_CNF[0] = 
        (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
      | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos)
      | (GPIO_PIN_CNF_PULL_Pullup    << GPIO_PIN_CNF_PULL_Pos)
      | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos)
      | (GPIO_PIN_CNF_DIR_Input      << GPIO_PIN_CNF_DIR_Pos); 	
			
  NRF_TWI1->EVENTS_RXDREADY = 0;
  NRF_TWI1->EVENTS_TXDSENT = 0;
  NRF_TWI1->PSELSCL = 0x00000002;  //SCL
  NRF_TWI1->PSELSDA = 0x00000000;  //SDA
  NRF_TWI1->FREQUENCY = 0x01980000; //100k
  NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TWI1->EVENTS_BB;
  NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_SUSPEND;
  NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Msk;
  NRF_TWI1->ENABLE = 1;
}

/******************************************************************************************************************/
Parents
  • You should set NRF_TWI1->ENABLE = 5 not 1, to enable the twi.

    Now you code will output the address. Remember to shift the address one bit right, since the last bit is for ACK/NACK (and is automatically shifted left in the TWI HW):

    NRF_TWI1->ADDRESS=(0x78 >> 1);
    

    Also, if you do not have a slave that ACK the address, it will only transmit the address and stop, so you will not see the data byte.

Reply
  • You should set NRF_TWI1->ENABLE = 5 not 1, to enable the twi.

    Now you code will output the address. Remember to shift the address one bit right, since the last bit is for ACK/NACK (and is automatically shifted left in the TWI HW):

    NRF_TWI1->ADDRESS=(0x78 >> 1);
    

    Also, if you do not have a slave that ACK the address, it will only transmit the address and stop, so you will not see the data byte.

Children
No Data
Related