Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I2C (TWI) ACK flag register use

Status
Not open for further replies.

Lauris

Newbie level 6
Joined
Apr 24, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Lithuania, Vlinius
Activity points
1,355
Hello eeryone,

one question apeared while trying to make full I2C(TWI) interupt based driver. main problem is after transmitting nACK when I can set it back inside ISR(); and don't leave I2C hanging with nACK in register that way uC being isolated from i2C line.


Code:
    case 0x40:	//SLA+R has been transmitted, ACK has been received
	  if (cnt_R >= TWI_rcv_sz)
	    TWCR &= ~(1 << 6);		//transmit nACK to inform about last receiving byte
	  TWCR |= (1 << 7);		//Eanble TWI, to continue transmition
	  if (TWCR & (1 << 6))
	    TWCR |= (1 << 6);	//reseting TWEA back to ACK
	  break;
would it make sence what I wrote ahead that nACK writed to registers, transfer started and after that swiching nACK flag back to ACK - sill nACK would be transfered? if not then how to do that inside interupt function. Any ideas?

P.S. this case is writed for Atmega8

Laurynas.
 

as far as i remember, if you send a NAK (via clearing TWEA) you only need to restore TWEA when you receive the STOP condition (0xA0 i think) and make sure that TWI is cleared ONLY at the end of your ISR.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top