Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: avr и rtc4574s
Форум разработчиков электроники ELECTRONIX.ru > Микроконтроллеры (MCs) > AVR
kostik2
доброго времени суток. вот работаю с RTC4574S. Все время в обработчике прерывани одни и теже события:

0x08 - start has been transmitted
0x48 - sla+r has been transmitted anf nack received

Вот что посылаю messageBuf[0]=0x10001100;

? Помогите разобраться.
smac
Цитата(kostik2 @ Apr 15 2009, 21:48) *
доброго времени суток. вот работаю с RTC4574S. Все время в обработчике прерывани одни и теже события:

0x08 - start has been transmitted
0x48 - sla+r has been transmitted anf nack received

Вот что посылаю messageBuf[0]=0x10001100;

? Помогите разобраться.

Вы уверены что нужно посылать в messageBuf[0] четыре байта? Т. е. у Вас сейчас в messageBuf[0] пишется в шестнадцатиричном представлении 0x10001100, может быть нужно так?
Код
messageBuf[0]=0b10001100;

А вообще, телепаты, как обычно в отпуске.
kostik2
void TWI_Master_Initialise(void)
{
TWBR= 0x0a; //set bit rate
TWSR= 0x00; //set prescale

//TWBR = TWI_TWBR; // Set bit rate register (Baudrate). Defined in header file.
//TWSR = TWI_TWPS; // Not used. Driver presumes prescaler to be 00.
TWDR = 0xFF; // Default content = SDA released.
TWCR = (1<<TWEN)| // Enable TWI-interface and release TWI pins.
(0<<TWIE)|(0<<TWINT)| // Disable Interupt.
(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)| // No Signal requests.
(0<<TWWC); //
}

#pragma interrupt_handler twi_isr:iv_TWI
void twi_isr(void)
{
static unsigned char TWI_bufPtr;

switch (TWSR)
{
case TWI_START: // START has been transmitted
case TWI_REP_START: // Repeated START has been transmitted
TWI_bufPtr = 0; // Set buffer pointer to the TWI Address location
case TWI_MTX_ADR_ACK: // SLA+W has been tramsmitted and ACK received
case TWI_MTX_DATA_ACK: // Data byte has been tramsmitted and ACK received
if(TWI_bufPtr < TWI_msgSize)
{
TWDR = TWI_buf[TWI_bufPtr++];
TWCR = (1<<TWEN)| // TWI Interface enabled
(1<<TWIE)|(1<<TWINT)| // Enable TWI Interupt and clear the flag to send byte
(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)| //
(0<<TWWC); //
}else // Send STOP after last byte
{
TWI_statusReg1.TWI_statusReg.lastTransOK = TRUE; // Set status bits to completed successfully.
TWCR = (1<<TWEN)| // TWI Interface enabled
(0<<TWIE)|(1<<TWINT)| // Disable TWI Interrupt and clear the flag
(0<<TWEA)|(0<<TWSTA)|(1<<TWSTO)| // Initiate a STOP condition.
(0<<TWWC); //
zz=1;
}
break;
case TWI_MRX_DATA_ACK: // Data byte has been received and ACK tramsmitted
//TWI_buf[TWI_bufPtr++] = TWDR;
zzz=TWDR;
case TWI_MRX_ADR_ACK: // SLA+R has been tramsmitted and ACK received
if (TWI_bufPtr < (TWI_msgSize-1) ) // Detect the last byte to NACK it.
{
TWCR = (1<<TWEN)| // TWI Interface enabled
(1<<TWIE)|(1<<TWINT)| // Enable TWI Interupt and clear the flag to read next byte
(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)| // Send ACK after reception
(0<<TWWC); //
}else // Send NACK after next reception
{
TWCR = (1<<TWEN)| // TWI Interface enabled
(1<<TWIE)|(1<<TWINT)| // Enable TWI Interupt and clear the flag to read next byte
(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)| // Send NACK after reception
(0<<TWWC); //
}
break;
case TWI_MRX_DATA_NACK: // Data byte has been received and NACK tramsmitted
//TWI_buf[TWI_bufPtr] = TWDR;
zzz=TWDR;
TWI_statusReg1.TWI_statusReg.lastTransOK = TRUE; // Set status bits to completed successfully.
TWCR = (1<<TWEN)| // TWI Interface enabled
(0<<TWIE)|(1<<TWINT)| // Disable TWI Interrupt and clear the flag
(0<<TWEA)|(0<<TWSTA)|(1<<TWSTO)| // Initiate a STOP condition.
(0<<TWWC); //
zz=1;
break;
case TWI_ARB_LOST: // Arbitration lost
TWCR = (1<<TWEN)| // TWI Interface enabled
(1<<TWIE)|(1<<TWINT)| // Enable TWI Interupt and clear the flag
(0<<TWEA)|(1<<TWSTA)|(0<<TWSTO)| // Initiate a (RE)START condition.
(0<<TWWC); //
break;
case TWI_MTX_ADR_NACK: // SLA+W has been tramsmitted and NACK received
case TWI_MRX_ADR_NACK: // SLA+R has been tramsmitted and NACK received
case TWI_MTX_DATA_NACK: // Data byte has been tramsmitted and NACK received
// case TWI_NO_STATE // No relevant state information available; TWINT = “0”
case TWI_BUS_ERROR: // Bus error due to an illegal START or STOP condition
default:
TWI_state = TWSR; // Store TWSR and automatically sets clears noErrors bit.
// Reset TWI Interface
TWCR = (1<<TWEN)| // Enable TWI-interface and release TWI pins
(0<<TWIE)|(0<<TWINT)| // Disable Interupt
(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)| // No Signal requests
(0<<TWWC);
zz=1; //
}

отсылаю messageBuf[0]=0b00110001;

в ответ: 08(start ok) 48(sla+r send and receive nack) ? не пойму в чем проблема....



не пойму что не так делаю......
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Invision Power Board © 2001-2025 Invision Power Services, Inc.