我正在尝试让 ATMEGA 324PA 作为 SMBus 从站运行。
我在 Pi 上使用以下代码:
import smbus as smbus
i2c = smbus.SMBus(1)
i2c_addr = 0x30
result = i2c.read_block_data( i2c_addr, reg )
在 AVR 上,我正在使用:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include "smb_slave.h"
#define SMB_COMMAND_RETURN_VENDOR_STRING 0x10
int main(void)
{
// Set data direction of PORTB as output and turn off LEDs.
DDRA = 0xff;
PORTA = 0xff;
// Initialize SMBus
SMBusInit();
SMBEnable();
// Enable interrupts globally
sei();
for (;;)
{
}
return 0;
}
void ProcessReceiveByte(SMBData *smb)
{
smb->txBuffer[0] = ~PIND;
smb->txLength = 1;
}
static void ReturnVendorString(SMBData *smb)
{
unsigned char *vendor = (unsigned char*) "Vendor\0";
unsigned char i;
unsigned char temp;
i = 0;
// Copy vendor ID string from EEPROM.
while ((temp = vendor[i]) != '\0')
{
i++;
smb->txBuffer[i] = temp;
}
smb->txBuffer[0] = i; // Byte count.
smb->txLength = i + 1; // Number of bytes to be transmitted including byte count.
smb->state = SMB_STATE_WRITE_READ_REQUESTED;
PORTA ^= 0x40; // debug
}
static void UndefinedCommand(SMBData *smb)
{
// Handle undefined requests here.
smb->error = TRUE;
smb->state = SMB_STATE_IDLE;
}
void ProcessMessage(SMBData *smb)
{
if (smb->state == SMB_STATE_WRITE_REQUESTED)
{
switch (smb->rxBuffer[0]) // Command code.
{
case SMB_COMMAND_RETURN_VENDOR_STRING: // Block read, vendor ID.
ReturnVendorString(smb);
break;
default:
UndefinedCommand(smb);
break;
}
}
else
{
smb->state = SMB_STATE_IDLE;
}
}
使用(gcc-adapted)版本: http: //www.atmel.com/images/AVR316.zip来自http://www.atmel.com/devices/ATMEGA324A.aspx?tab=documents
正如我的逻辑分析仪显示的那样,有些东西正在部分工作:
但我认为我做错了什么,因为 AVR 没有确认 READ,也没有延长时钟,也没有发送响应。
我接下来应该看哪里?
我对 RasPi 上的 Python smbus 模块有信心吗?
我所看到的可能与https://github.com/raspberrypi/linux/issues/254有关吗?