реклама на сайте
подробности

 
 
 
Reply to this topicStart new topic
> avr и rtc4574s, проблема обмена с rtc4574 по i2c
kostik2
сообщение Apr 15 2009, 17:48
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 61
Регистрация: 16-02-06
Пользователь №: 14 375



доброго времени суток. вот работаю с RTC4574S. Все время в обработчике прерывани одни и теже события:

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

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

? Помогите разобраться.
Go to the top of the page
 
+Quote Post
smac
сообщение Apr 15 2009, 19:14
Сообщение #2


Частый гость
**

Группа: Участник
Сообщений: 149
Регистрация: 2-06-08
Из: Москва
Пользователь №: 38 003



Цитата(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;

А вообще, телепаты, как обычно в отпуске.

Сообщение отредактировал smac - Apr 15 2009, 19:16
Go to the top of the page
 
+Quote Post
kostik2
сообщение Apr 18 2009, 15:23
Сообщение #3


Участник
*

Группа: Участник
Сообщений: 61
Регистрация: 16-02-06
Пользователь №: 14 375



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) ? не пойму в чем проблема....



не пойму что не так делаю......
Прикрепленные файлы
Прикрепленный файл  rtc4574_manual1.pdf ( 288.88 килобайт ) Кол-во скачиваний: 64
 
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 22nd July 2025 - 22:40
Рейтинг@Mail.ru


Страница сгенерированна за 0.01387 секунд с 7
ELECTRONIX ©2004-2016