项目需要通过IIC来跟个外部芯片通信,按照样例模板建立个简单的工程进行测试,结果使用示波器都看到SDA和SCL线上的波形(我单独写个程序测试SDA和SCL,管脚配置是没有问题的)。请大家过来看看可能是什么原因,谢谢。
1. IIC模块的配置,很简单,就直接用样例的模块来:
2. 代码:也是样例的代码,只是删除了LCD部分的程序
#include <device.h>
/* The I2C Slave address by default in a PSoC device is 8 */
#define I2C_SLAVE_ADDRESS (8u)
/* Set the write buffer length to be 16 bits or 2 bytes */
#define WR_BUFFER_SIZE (2u)
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
* main function performs following functions:
* 1. Starts all used components.
* 2. Controls sequencing of ADC inputs.
* 3. Reads ADC converted data, sends this data via a I2C Master.
* 4. Displays ADC converted data on Character LCD.
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
int main()
{
uint8 temp;
uint8 sample_segment[WR_BUFFER_SIZE];
uint16 sample_full;
I2CM_Start();
for(;;)
{
sample_segment[0] = 0xEE;
sample_segment[1] = 0xDD;
do
{
/* The syntax below automatically writes a buffer of data to a slave
* device from start to stop.
*/
temp = I2CM_MasterWriteBuf(I2C_SLAVE_ADDRESS, (uint8 *)sample_segment,
WR_BUFFER_SIZE, I2CM_MODE_COMPLETE_XFER);
}
while (temp != I2CM_MSTR_NO_ERROR);
/* Wait for the data transfer to complete */
while(I2CM_MasterStatus() & I2CM_MSTAT_XFER_INP);
temp = I2CM_MasterClearStatus();
/* Delay introduced for ease of reading LCD */
CyDelay(2000u/*ms*/);
} /* End forever loop */
} /* End main */
3. 问题现象:程序运行时,用示波器检测,看不到SDA和SCL上的波形。但是我这边单独控制SDA和SCL是可以用波形产生的,所以管脚配置是没有错的。 为什么用IIC模块就不得?
|