sam3x twi

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I work with the display on i2c. The wire is about 30 centimeters, if there are pickups then the twi freezes. Rebooting the controller does not help. If you disconnect the wire SDA the data transfer will resume, nothing else helps!

void Twi0::reset(void)
{
 uint32_t temp = TWI0->TWI_CWGR;
 TWI0->TWI_CR = TWI_CR_SWRST;
 PDC_TWI0->PERIPH_PTCR = PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS;
 PDC_TWI0->PERIPH_RCR  = 0;
 PDC_TWI0->PERIPH_TCR  = 0;
 TWI0->TWI_CR = TWI_CR_MSEN;//
 TWI0->TWI_CWGR = temp;	
 twiError = 0;	
}

I reboot with this code but it doesn’t give anything, only bus SDA disconnection helps

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void Twi0::write(uint8_t addr, uint8_t *buf, uint8_t len)
{
 uint32_t timeOut = TWI_TIMEOUT;	
 TWI0->TWI_MMR = 0;
 TWI0->TWI_MMR = TWI_MMR_DADR(addr);
 PDC_TWI0->PERIPH_TPR = (uint32_t)buf;  
 PDC_TWI0->PERIPH_TCR = len; 
 PDC_TWI0->PERIPH_PTCR = PERIPH_PTCR_TXTEN;
 while(!(TWI0->TWI_SR & TWI_SR_ENDTX))
      {
	   if(!timeOut--)
	     {
		  twiError = 1;
		  return;	 
		 }	  
	  }
 PDC_TWI0->PERIPH_PTCR = PERIPH_PTCR_TXTDIS;
 timeOut = TWI_TIMEOUT;
 while(!(TWI0->TWI_SR & TWI_SR_TXRDY))// Wait for last acknowledge
      {
	   if(TWI0->TWI_SR & TWI_SR_NACK) twiError = 1; 
	   if(!timeOut--)
	     {
		  twiError = 1;
		  return;
	     }
	  }
 TWI0->TWI_CR = TWI_CR_STOP;
 timeOut = TWI_TIMEOUT; 
 while(!(TWI0->TWI_SR & TWI_SR_TXCOMP))
      {
	   if(!timeOut--)
		 {
		  twiError = 1;
		  return;
		 }  
	  } 
} //*/