Other Parts Discussed in Thread: HALCOGEN
主题中讨论的其他器件:HALCOGEN
你(们)好。
我正在寻找一个基于 Halcogen 生成的 API 的从器件发送和接收的示例代码。 以下是我的初稿。 请注意、这是假设接线和硬件按预期工作、因此不会捕获错误。
/* In high level driver */
IO_I2C_ret_E IO_I2C_transceive(const uint8_t * txBuffer,
const uint16_t txLength,
const uint8_t * rxBuffer,
const uint16_t rxLength)
{
IO_I2C_ret_E ret = IO_I2C_RET_ERROR;
/* Set direction to Transmitter */
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
/* Configure Data count */
i2cSetCount(i2cREG1, (uint32_t) txLength);
/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, Slave_Add);
/* Start transmit*/
IO_I2C_semaphoneTake(); // take semaphore to be returned by isr
i2cSetStart(i2cREG1); // Start the transmission:
/* send data */
IO_I2C_semaphoneTake(); // take semaphore to be returned by isr
i2cSend(i2cREG1, (uint32_t) txLength, txBuffer);
if (rxLength > 0)
{
/* Set direction to Transmitter */
i2cSetDirection(i2cREG1, I2C_RECEIVER);
/* Configure Data count */
i2cSetCount(i2cREG1, (uint32_t) rxLength);
/* Start transmit*/
IO_I2C_semaphoneTake(); // take semaphore to be returned by isr
i2cSetStart(i2cREG1); // Start the transmission:
/* receive data */
IO_I2C_semaphoneTake(); // take semaphore to be returned by isr
i2cSend(i2cREG1, (uint32_t) rxLength, rxBuffer);
}
/* set stop */
i2cSetStop(i2cREG1);
ret = IO_I2C_RET_SUCCESS;
return ret;
}
/* In Halcogen generated notification.c */
#pragma WEAK(i2cNotification)
void i2cNotification(i2cBASE_t *i2c, uint32 flags)
{
/* enter user code between the USER CODE BEGIN and USER CODE END. */
/* USER CODE BEGIN (21) */
if( (i2cREG1 == i2c))
{
IO_I2C_semaphoreGive();
}
/* USER CODE END */
}
如果有一个类似的参考代码、我可以参考、那将会很好。 下面是我的问题列表:
问题1:在论坛的另一个主题中,您的 Guru 提到 i32cSetStart()将发送#1开始条件、#2从器件地址和#3 R/W 位。 它是否仍然是真的?
Q2: i32cSetStart()是否也在中断模式下运行? 这意味着该函数会立即返回、并在发送从器件地址时生成中断?
Q3:在 i2cSend()和 i2cReceive()中,我将它们称为 API 函数,有使用中断的实现。 在中断实现中、它使用静态结构 g_i2cTransfer_t 来保持数据指针和长度。 但是 、API 函数仅将初始值分配给结构体并退出、但我看不到任何循环的代码、也看不到在中断通知中调用的 API 函数。 我缺少什么吗? 或者是否有一个 DMA 机制自动处理多字节读取/写入、这样一个调用如下:
i2cSend (i2cREG1、10、&data);
是否会在传输全部10个字节后调用 i2cNotification()?

