简体   繁体   English

使用mcp2210从atmel m90e26s读取地址

[英]read address from atmel m90e26s using mcp2210

I'm working on a school project where we want to monitor the energy consumption using the atmel M90e26s chip. 我正在做一个学校项目,我们想使用atmel M90e26s芯片监控能耗。

I used the mcp2210 library and wrote this little testscript: 我使用了mcp2210库并编写了这个小脚本:

void talk(hid_device* handle) {
ChipSettingsDef chipDef;

//set GPIO pins to be CS
chipDef = GetChipSettings(handle);

for (int i = 0; i < 9; i++) {
    chipDef.GP[i].PinDesignation = GP_PIN_DESIGNATION_CS;
    chipDef.GP[i].GPIODirection = GPIO_DIRECTION_OUTPUT;
    chipDef.GP[i].GPIOOutput = 1;
}
int r = SetChipSettings(handle, chipDef);

//configure SPI
SPITransferSettingsDef def;
def = GetSPITransferSettings(handle);

//chip select is GP4
def.ActiveChipSelectValue = 0xffef;
def.IdleChipSelectValue = 0xffff;
def.BitRate = 50000l;
def.SPIMode = 4; 

//enable write
byte spiCmdBuffer[3];


//read 8 bytes
def.BytesPerSPITransfer = 3;
r = SetSPITransferSettings(handle, def);
if (r != 0) {
    printf("Errror setting SPI parameters.\n");
    return;
}

spiCmdBuffer[0] = 0x01; //0000 0011 read
spiCmdBuffer[1] = 0x00; //address 0x00

SPIDataTransferStatusDef def1 = SPISendReceive(handle, spiCmdBuffer, 3);

for (int i = 0; i < 8; i++)
    printf("%hhu\n", def1.DataReceived[i]);
}

Any address I try, I get no respons. 我尝试的任何地址,我都没有回应。 The problem seems this: 问题似乎是这样的:

spiCmdBuffer[0] = 0x01; //0000 0011 read
spiCmdBuffer[1] = 0x00; //address 0x00

I know from the datasheet that the spi interface looks like this: spi interface 我从数据表中知道spi接口看起来像这样: spi接口

Can somebody help me to find the address registers from the atm90e26? 有人可以帮我从atm90e26查找地址寄存器吗? All the addresses look like '01H', but that is not hexadecimal and it's not 7 bit either. 所有地址看起来都像“ 01H”,但这不是十六进制,也不是7位。

Yes, as you suspected the problem is in how you set the contents of spiCmdBuffer. 是的,您怀疑问题在于如何设置spiCmdBuffer的内容。 The ATM90E26 expects both the read/write flag and the register address to be in the first byte of the SPI transaction: the read/write flag must be put at the most significant bit (value 1 to read from a register, value 0 to write to a register), while the register address is in the 7 remaining bits. ATM90E26期望读/写标志和寄存器地址都在SPI事务的第一个字节中:读/写标志必须放在最高有效位(从寄存器读取的值为1,从写入值为0寄存器),而寄存器地址在剩余的7位中。 So for example to read the register at address 0x01 (SysStatus) the code would look like: 因此,例如,要读取地址为0x01(SysStatus)的寄存器,代码将如下所示:

spiCmdBuffer[0] = 0x80 | 0x01;  // read System Status

The 0x80 value sets the read/write flag in the most significant bit, and the other value indicates the register address. 0x80值将最高有效位设置为读/写标志,另一个值指示寄存器地址。 The second and third bytes of a 3-byte read sequence don't need to be set to anything, since they are ignored by the ATM90E26. 3字节读取序列的第二和第三字节不需要设置为任何值,因为ATM90E26会忽略它们。

After calling SPISendReceive(), to extract the register contents (16 bits) you have to read the second and third byte (MSB first) from the data received in the read transaction, like below: 调用SPISendReceive()之后,要提取寄存器内容(16位),必须从读取的事务中接收的数据中读取第二个和第三个字节(MSB优先),如下所示:

uint16_t regValue = (((uint16_t)def1.DataReceived[1]) << 8) | def1.DataReceived[2];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM