📄 main.c
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Date First Issued : 16/05/2003
* Description : example using the I2C library for transmission of buffers
* between the two I2C modules
********************************************************************************
* History:
* 16/05/03 : Created.
*******************************************************************************/
#include "71x_lib.h"
#define I2C0_SCL 0x2000
#define I2C0_SDA 0x4000
#define I2C1_SCL 0x0004
#define I2C1_SDA 0x0008
void Main(void)
{
I2C_Tx_Status SendResult;
u8 bTableau[10] = {1, 2, 3, 4, 15};
u8 *pBuffer = bTableau;
#ifdef DEBUG
debug();
#endif
//Configure the SDA And the SCL pin of the I2C0 and I2C1 to alternate function Open Drain
GPIO_Config(GPIO1, I2C0_SCL, GPIO_AF_OD);
GPIO_Config(GPIO1, I2C0_SDA, GPIO_AF_OD);
GPIO_Config(GPIO0, I2C1_SCL, GPIO_AF_OD);
GPIO_Config(GPIO0, I2C1_SDA, GPIO_AF_OD);
//configure the Interrupt to be used
EIC_IRQChannelPriorityConfig(I2C1_IRQChannel, 0x05);
EIC_IRQChannelConfig(I2C1_IRQChannel, ENABLE);
EIC_IRQConfig(ENABLE);
EIC_IRQChannelPriorityConfig(I2C1ITERR_IRQChannel, 0x05);
EIC_IRQChannelConfig(I2C1ITERR_IRQChannel, ENABLE);
EIC_IRQConfig(ENABLE);
//Configure the I2C1 module
I2C_Init(I2C1);
I2C_FCLKConfig(I2C1);
//Enable the I2C1
I2C_OnOffConfig(I2C1, ENABLE);
//Configure the I2C1 speed
I2C_SpeedConfig(I2C1, 100000);
//Configure the I2C1 address (to be used specially when this cell has to be adressed)
I2C_AddressConfig(I2C1,0x3C0, I2C_Mode10);
//Enable the Acknowledge
I2C_AcknowledgeConfig(I2C1, ENABLE);
// Enable the interrupt generation
I2C_ITConfig(I2C1, ENABLE);
//Configure I2C0 module
I2C_Init(I2C0);
I2C_FCLKConfig(I2C0);
//Enable the I2C0
I2C_OnOffConfig(I2C0, ENABLE);
//Configure the I2C0 speed
I2C_SpeedConfig(I2C0, 100000);
//Configure the I2C0 address (to be used specially when this cell has to be adressed)
I2C_AddressConfig(I2C0,0x3A0, I2C_Mode10);
//Enable Start generation
I2C_STARTGenerate(I2C0, ENABLE);
//Wait til the SB flag is set to confirm the START generation
while(I2C_FlagStatus(I2C0, DIRECT, I2C_SB) == RESET);
//Send the slave address
I2C_AddressSend(I2C0, 0xc0, I2C_Mode7, I2C_TX);
//Test the end of address transmission
while(I2C_FlagStatus(I2C0, DIRECT, I2C_ENDAD) == RESET);
I2C_FlagClear(I2C0, I2C_ENDAD);
//Send Data to the slave
SendResult = I2C_BufferSend(I2C0, pBuffer, 5);
//Stop the communication
I2C_STOPGenerate(I2C0, ENABLE);
//Disable I2C0 and I2C1
I2C_OnOffConfig(I2C0, DISABLE);
I2C_OnOffConfig(I2C1, DISABLE);
}
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -