#include <stm32f0xx.h>
uint8_t tmp;
uint16_t Tx_Idx1=0;
uint8_t Buffer_Rx[256];
uint8_t numOfSend;
uint8_t countOfSend;
uint8_t Buffer_Tx1[] = {
0x04, 0x11, 0x33, 0x43, \
0x23, 0xAB, 0x03, 0x4D, 0x9D, 0x47, 0xC6, 0x1F, 0xF1, 0x6D, 0x54, 0xA8, 0xF5, 0x75, 0x36, 0x9D, \
0x34, 0x9D, 0x24, 0xDE, 0xA2, 0x4A, 0x82, 0xA1, 0x04, 0x18, 0xD4, 0x19, 0x4C, 0xC2, 0xF3, 0x5E, \
0xCE, 0x24, 0xB6, \
0x23, 0x5D, 0x5B, 0x41, 0xBF, 0x5A, 0x2A, 0x95, 0x75, 0x0A, 0xD5, 0xF5, 0x34, 0xAB, 0xDE, 0x90, \
0x48, 0xFE, 0x28, 0xF9, 0xEC, 0x9C, 0x49, 0xCE, 0x3A, 0x0F, 0xB7, 0xCD, 0x1A, 0xE7, 0x88, 0xF1, \
0x53, 0xED, 0x2B, \
0x04, 0x00, 0x03, 0x40, \
0x04, 0x00, 0x03, 0x40, \
0x04, 0x11, 0x33, 0x43, \
0x04, 0x00, 0x03, 0x40, \
0x04, 0x11, 0x33, 0x43, \
0x04, 0x00, 0x03, 0x40, \
0x04, 0x00, 0x03, 0x40, \
0x04, 0x11, 0x33, 0x43, \
0x04, 0x00, 0x03, 0x40, \
0x23, 0x3F, 0x09, 0x75, 0x39, 0xC9, 0x10, 0x84, 0x7D, 0x4D, 0x24, 0x1C, 0xF2, 0x1F, 0xD5, 0xF4, \
0xEE, 0xAB, 0x1F, 0x1B, 0xAE, 0x21, 0x4F, 0x4B, 0x65, 0x10, 0xF6, 0x16, 0xF1, 0x94, 0x5A, 0x99, \
0xC7, 0xB5, 0x05, \
0x04, 0x11, 0x33, 0x43, \
0x23, 0xAD, 0xB3, 0xE6, 0x97, 0x58, 0x2C, 0x88, 0x9D, 0x7C, 0x44, 0x7A, 0x6C, 0xC0, 0xBF, 0x11, \
0x5D, 0xD4, 0x9A, 0x9A, 0x58, 0x80, 0xB2, 0xE8, 0xAF, 0x56, 0xB6, 0xA7, 0x09, 0xB4, 0x43, 0x33, \
0x3D, 0xA3, 0x3A, \
0x04, 0x00, 0x03, 0x40, \
0x23, 0x5E, 0x06, 0xB3, 0x48, 0x76, 0xB0, 0x60, 0x71, 0x27, 0x8F, 0xFC, 0x00, 0x62, 0x23, 0xBB, \
0x69, 0x92, 0x19, 0x9F, 0x4A, 0xF2, 0xF0, 0x23, 0x21, 0xEC, 0x81, 0x45, 0x98, 0xA6, 0x3D, 0xD4, \
0x6C, 0x7E, 0x90
};
//ham ngat I2C1
void I2C1_IRQHandler(void) {
//ham ngat I2C1
//kiem tra xem cai gi *** ra ngat
uint32_t isr;
isr=I2C1->ISR;
//kiem tra xem co trong che do SLAVE khong
//ADDRESS matched
if(isr&I2C_ISR_ADDR) {
//kiem tra chieu truyen du lieu
if(isr&I2C_ISR_DIR) {
//chieu truyen du lieu
//slave truyen du lieu
numOfSend=Buffer_Tx1[Tx_Idx1];
countOfSend=0;
} else {
//slave nhan du lieu
//=======================
}
isr=0;
}
if(isr & I2C_ISR_TXE) {
++countOfSend;
if(countOfSend>numOfSend) {
//==================================================================
I2C1->TXDR = 0xFF;
} else {
tmp=Buffer_Tx1[Tx_Idx1++];
I2C1->TXDR = tmp;
//==================================================================
}
isr=0;
}
if(isr & I2C_ISR_RXNE) {
tmp=I2C1->RXDR;
isr=0;
}
if(isr & I2C_ISR_STOPF) {
I2C1->CR1=I2C_CR1_PE;
isr=0;
}
//kiem tra loi
if(isr & I2C_ISR_ARLO) {
I2C1->ICR |= I2C_ICR_ARLOCF;
isr=0;
}
if(isr & I2C_ISR_BERR) {
I2C1->ICR |= I2C_ICR_BERRCF;
isr=0;
}
if(isr & I2C_ISR_OVR) {
I2C1->ICR |= I2C_ICR_OVRCF;
isr=0;
}
}