Stm32 I2C - FabLabSeoul/WingProject GitHub Wiki

이 글은 Stm32 Value line discoveryλ³΄λ“œ μ „μš© μ„€λͺ…이닀.

I2C μ—°κ²°. ( !!μžŠμ§€λ§μž. SCL, SDA 핀에 Pull-Up 저항을 κΌ­ λ‹¬μ•„μ€˜μ•Ό ν•œλ‹€. )

I2C(inter integrated circuit)λŠ” μ„  두가λ‹₯만 μ—°κ²°ν•˜λ©΄ 정보λ₯Ό 주고받을 수 μžˆλŠ” 톡신 ν”„λ‘œν† μ½œμ„ λ§ν•œλ‹€. 두 선을 각각 SCL(Serial CLock), SDA(Serial DAta)라고 λ§ν•œλ‹€. 톡신을 μ‹œμž‘ν•˜κ³  λŠλŠ” Master와 정보λ₯Ό μ£Όκ³  받을 수 μžˆλŠ” Slave 역할이 μžˆλ‹€. (λ¬Όλ‘  λ§ˆμŠ€ν„°λ„ 정보λ₯Ό 주고받을 수 μžˆλ‹€.) λ§ˆμŠ€ν„° ν•˜λ‚˜μ— 두 κ°œμ΄μƒμ˜ μŠ¬λž˜μ΄λΈŒκ°€ 뢙을 수 있기 λ•Œλ¬Έμ—, μ „μžκΈ°κΈ°μ˜ λ‚΄λΆ€ μž₯μΉ˜λ“€κ°„μ˜ 톡신에 많이 쓰인닀.

ν•˜λ‚˜μ˜ λ§ˆμŠ€ν„°μ— 두 κ°œμ΄μƒμ˜ μŠ¬λž˜μ΄λΈŒκ°€ 뢙을 수 있기 λ•Œλ¬Έμ—, λˆ„κ°€ 정보λ₯Ό 받을지에 λŒ€ν•œ 정보(Address)λ₯Ό 솑신해야 ν•œλ‹€. λ˜ν•œ ν†΅μ‹ μ˜ 신뒰성을 λ†’μ΄κΈ°μœ„ν•΄ HandShake λ°©μ‹μ˜ ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•˜κ³  μžˆλ‹€. λ‹€μ‹œλ§ν•΄, 정보λ₯Ό μ†‘μ‹ ν•˜κ³  λ‚œ ν›„, ACK이벀트λ₯Ό λ°›μ•„μ•Ό, λ‹€μŒ 정보λ₯Ό 솑신할 수 μžˆλ‹€. 접속을 μ‹œμž‘ν•˜κ³ , 접속을 λŠλŠ” 것도 λ§ˆμ°¬κ°€μ§€λ‹€. (ν•Έλ“œμ„Έμ΄ν‚Ή 방식 λ•Œλ¬Έμ— μ½”λ“œκ°€ λ³΅μž‘ν•˜λ‹€.)

글을 계속 μ½μ–΄λ‚˜κ°€κΈ° 전에 λ¨Όμ € λ‹€μŒ λ¬Έμ„œλ“€μ„ μ½μ–΄λ³΄μž.

I2C 기본 예제

μ•žμœΌλ‘œ μ„€λͺ…ν•  μ˜ˆμ œλŠ” STM32\stm32vldiscovery_package\Project\Examples\I2C 폴더에 μžˆλ‹€.

Stm32 MCU의 I2C 포트 두 개λ₯Ό μ‚¬μš©ν•˜μ—¬ μ„œλ‘œ ν†΅μ‹ ν•˜λŠ” 예제λ₯Ό 보여쀀닀. I2C1은 λ§ˆμŠ€ν„°κ°€ 되고, I2C2λŠ” μŠ¬λž˜μ΄λΈŒκ°€ λœλ‹€. (I2Cλ₯Ό μ‰½κ²Œ μ„€λͺ…ν•˜κΈ° μœ„ν•œ μ˜ˆμ œμ΄μ§€, 같은 MCUμ—μ„œ I2C ν†΅μ‹ ν•˜λŠ” κ²½μš°λŠ” μ—†λ‹€.)

  • PB6 : I2C1_SCL (λ§ˆμŠ€ν„°)
  • PB7 : I2C1_SDA (λ§ˆμŠ€ν„°)
  • PB10 : I2C2_SCL (슬래이브)
  • PB11 : I2C2_SDA (슬래이브)

각 ν¬νŠΈλŠ” λ‹€μŒκ³Ό μ—°κ²°ν•œλ‹€.

  • PB6 - PB10
  • PB7 - PB11

즉, SCL은 SCL끼리, SDAλŠ” SDA끼리 μ—°κ²°ν•œλ‹€. I2C1 μ—μ„œ I2C2둜 데이타λ₯Ό μ „μ†‘ν•΄μ„œ, μ˜¬λ°”λ‘œ μ „μ†‘λ˜μ—ˆλŠ”μ§€ κ²€μ‚¬ν•˜λŠ” μ˜ˆμ œλ‹€. μ „μ†‘ν•˜λŠ” μ •λ³΄λŠ” 1λ°”μ΄νŠΈ 크기이고, {1,2,3,4} 4개의 정보λ₯Ό μˆœμ„œλŒ€λ‘œ 보낸닀.

클럭 μ΄ˆκΈ°ν™”

I2C도 ν΄λŸ­μ„ μ„€μ •ν•΄μ€˜μ•Ό ν•œλ‹€. PB6,7,10,11 포트λ₯Ό μ‚¬μš©ν•˜κΈ° λ•Œλ¬Έμ—, GPIOB 포트 ν΄λŸ­λ„ μ„€μ •ν•œλ‹€.

void RCC_Configuration(void)
{
  /* Enable peripheral clocks ------------------------------------------------*/
  /* GPIOB Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  /* I2C1 and I2C2 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 | RCC_APB1Periph_I2C2, ENABLE);
}

GPIO μ„€μ •

I2Cλ₯Ό μ‚¬μš©ν•  포트 PB6,7,10,11 을 μ„€μ •ν•œλ‹€. I2C ν¬νŠΈλŠ” μ •ν•΄μ Έ μžˆλ‹€. ν…Œμ΄λΈ”μ€ λ‹€μŒκ³Ό κ°™λ‹€.

(Stm32f103μ‘μš©.pdf, page 220)

PB6,7(I2C1), PB10,11(I2C2) 포트λ₯Ό Alternate-Function λͺ¨λ“œλ‘œ μ„€μ •ν•œλ‹€.

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure I2C1 pins: SCL and SDA ----------------------------------------*/
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configure I2C2 pins: SCL and SDA ----------------------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
}

I2C μ„€μ •

I2C1,2 두 개의 I2Cλͺ¨λ“ˆμ΄ μžˆλ‹€. μ–΄λ–€ λͺ¨λ“ˆμ„ μ‚¬μš©ν• μ§€ μ„ νƒν•˜κ³ , I2Cμ£Όμ†Œλ₯Ό μ„€μ •ν•œλ‹€. μ£Όμ†Œκ°€ μ—†μœΌλ©΄ 정보λ₯Ό 받을 수 μ—†λ‹€. 7λΉ„νŠΈμ™€ 10λΉ„νŠΈ μ£Όμ†Œ νƒ€μž… 쀑 ν•˜λ‚˜λ₯Ό μ„ νƒν•˜μž. μ£Όμ†Œ νƒ€μž…μ— 따라 전솑 ν”„λ‘œν† μ½œμ΄ λ°”λ€ŒκΈ° λ•Œλ¬Έμ— μ£Όμ˜ν•΄μ•Ό ν•œλ‹€.

I2C 섀정에 κ΄€ν•œ μžμ„Έν•œ λ‚΄μš©μ€ 맀뉴얼을 μ°Έκ³ ν•˜μž.

#define I2C1_SLAVE_ADDRESS7    0x30
#define I2C2_SLAVE1_ADDRESS7   0x30
#define ClockSpeed             200000
I2C_InitTypeDef  I2C_InitStructure;

  /* Enable I2C1 and I2C2 ----------------------------------------------------*/
  I2C_Cmd(I2C1, ENABLE);
  I2C_Cmd(I2C2, ENABLE);

  /* I2C1 configuration ------------------------------------------------------*/
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;
  I2C_Init(I2C1, &I2C_InitStructure);
  /* I2C2 configuration ------------------------------------------------------*/
  I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE1_ADDRESS7;
  I2C_Init(I2C2, &I2C_InitStructure);

I2Cλ₯Ό μ΄μš©ν•œ 데이타 전솑

I2CλŠ” λ§ˆμŠ€ν„° λͺ¨λ“œμΌ λ•Œμ™€ 슬래이브 λͺ¨λ“œμΌ λ•Œμ— 따라 정보λ₯Ό μ†‘μˆ˜μ‹ ν•˜λŠ” 방식이 λ‹€λ₯΄λ‹€. 이 μ˜ˆμ œμ—μ„œ λ§ˆμŠ€ν„°λŠ” 솑신(Transmitter)만 ν•œλ‹€. μŠ¬λž˜μ΄λΈŒλŠ” 정보λ₯Ό μˆ˜μ‹ (Receiver)만 ν•œλ‹€. I2C ν”„λ‘œν† μ½œμ€ λ‹€μŒμ˜ 과정을 거쳐 정보λ₯Ό μ†‘μˆ˜μ‹ ν•˜κ²Œ λœλ‹€. λ§ˆμŠ€ν„°, 슬래이브 λͺ¨λ‘ 7bit-address λͺ¨λ“œλ‹€. μžμ„Έν•œ λ‚΄μš©μ€ 맀뉴얼을 μ°Έκ³ ν•˜μž.

I2C ν”„λ‘œν† μ½œμ˜ 데이터 전솑 과정은 λ‹€μŒκ³Ό κ°™λ‹€.

  • λ§ˆμŠ€ν„°κ°€ μŠ¬λ ˆμ΄λΈŒμ— 전솑을 μ‹œμž‘ν•œλ‹€λŠ” ν‘œν˜„ - Start
  • 전솑 λͺ©μ μ§€μ˜ μ£Όμ†Œ ν‘œν˜„ - Address
  • 전솑 λͺ©μ  ν‘œν˜„(μ½κΈ°μš©μΈκ°€ λ˜λŠ” μ“°κΈ°μš©μΈκ°€) - R/W
  • 전솑 데이터 ν‘œν˜„ - Data
  • μŠ¬λ ˆμ΄λΈŒκ°€ μ •μƒμ μœΌλ‘œ 데이터λ₯Ό μˆ˜μ‹ ν–ˆλ‹€λŠ” 응닡 ν‘œν˜„ - Ack
  • 전솑 μ’…λ£Œ ν‘œν˜„ - Stop

I2C 톡신 μ‹œμž‘, I2C1-2κ°„ 톡신을 μ—°κ²°ν•œλ‹€.

I2C1 μ—μ„œ Startλ₯Ό μ‹œμž‘ν•˜κ³ , I2C2λ‘œλΆ€ν„° 응닡이 올 λ•ŒκΉŒμ§€ λŒ€κΈ°ν•œλ‹€. 이 과정은 μœ„μ— μžˆλŠ” μ‹œν€€μŠ€ λ‹€μ΄μ–΄κ·Έλž¨μ„ κ·ΈλŒ€λ‘œ λ”°λ₯Έλ‹€. (μ†ŒμŠ€μƒμ— λ‚˜μ˜€λŠ” EV1은 μ‹œν€€μŠ€ λ‹€μ΄μ–΄κ·Έλž¨μ˜ EV8_1 κ³Ό κ°™λ‹€.)

  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 
  /* Send I2C2 slave Address for write */
  I2C_Send7bitAddress(I2C1, I2C2_SLAVE1_ADDRESS7, I2C_Direction_Transmitter);
  /* Test on I2C2 EV1 and clear it */
  while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED));  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); 

I2C 데이타 μ†‘μˆ˜μ‹ 

I2C1μ—μ„œ 데이타λ₯Ό 보내고, I2C2λŠ” 데이타λ₯Ό λ°›λŠ”λ‹€. 7bit address master transmitter인 I2C1은 I2C1_Buffer1_Tx[] 배열에 μ €μž₯된 정보λ₯Ό ν•˜λ‚˜μ”© μ†‘μ‹ ν•œλ‹€. 7bit address slave receiver인 I2C2λŠ” λ§ˆμŠ€ν„°λ‘œλΆ€ν„° λ„˜μ–΄μ˜¨ 정보λ₯Ό ν•˜λ‚˜μ”© λ°›μ•„μ„œ I2C2_Buffer1_Rx[] 배열에 μ €μž₯ν•œλ‹€. 이 과정은 μœ„μ— μžˆλŠ” μ‹œν€€μŠ€ λ‹€μ΄μ–΄κ·Έλž¨μ„ κ·ΈλŒ€λ‘œ λ”°λ₯Έλ‹€.

uint8_t I2C1_Buffer1_Tx[BufferSize] = {1,2,3,4};
uint8_t I2C2_Buffer1_Rx[BufferSize];
uint8_t Tx_Idx = 0, Rx_Idx = 0;

  /* Send data */
  while (Rx_Idx < BufferSize)
  {
    /* Send I2C1 data */
    I2C_SendData(I2C1, I2C1_Buffer1_Tx[Tx_Idx++]);
    /* Test on I2C2 EV2 and clear it */
    while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_BYTE_RECEIVED));  
    /* Store received data on I2C2 */
    I2C2_Buffer1_Rx[Rx_Idx++] = I2C_ReceiveData(I2C2);
    /* Test on I2C1 EV8 and clear it */
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); 
  }

I2C 톡신 μ’…λ£Œ

λ§ˆμŠ€ν„°μΈ I2C1μ—μ„œ Stop 메세지λ₯Ό 보내고 접속을 λŠλŠ”λ‹€. μŠ¬λž˜μ΄λΈŒλ„ 접속이 λŠκ²ΌλŠ”μ§€ ν™•μΈν•˜κ³  톡신을 μ’…λ£Œν•œλ‹€.

  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);
  /* Test on I2C2 EV4 and clear it */
  while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_STOP_DETECTED)); 
  /* Clear I2C2 STOPF flag: read operation to I2C_SR1 followed by a 
     write operation to I2C_CR1 */
  (void)(I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF));
  I2C_Cmd(I2C2, ENABLE);    

예제 μ½”λ“œ 전체

이 μ˜ˆμ œλŠ” STM32\stm32vldiscovery_package\Project\Examples\I2C 폴더에 μžˆλ‹€.

I2C 포트 두 개λ₯Ό μ‚¬μš©ν•˜μ—¬ μ„œλ‘œ ν†΅μ‹ ν•˜λŠ” 예제λ₯Ό 보여쀀닀. 포트 PB6,7(I2C1)은 λ§ˆμŠ€ν„°κ°€ 되고, 포트 PB10,11(I2C2)은 μŠ¬λž˜μ΄λΈŒκ°€ λœλ‹€. 각각의 SCL, SDA포트λ₯Ό μ—°κ²°ν•΄μ„œ ν…ŒμŠ€νŠΈ ν•΄λ³΄μž. 그리고 SCL, SDA ν¬νŠΈμ— ν’€μ—… 저항을 달아야 μ œλŒ€λ‘œ λ™μž‘ν•œλ‹€.

νšŒλ‘œκ΅¬μ„±μ€ https://harinadha.wordpress.com/2012/07/24/i2c_problem-mpu6050/ λ₯Ό μ°Έμ‘°ν•˜μž.

(I2Cλ₯Ό μ‰½κ²Œ μ„€λͺ…ν•˜κΈ° μœ„ν•œ μ˜ˆμ œμ΄μ§€, 같은 MCUμ—μ„œ I2C ν†΅μ‹ ν•˜λŠ” κ²½μš°λŠ” μ—†λ‹€.)

(while문으둜 ACKλ₯Ό 기닀리기 λ•Œλ¬Έμ— λ§Œμ•½ I2C선이 λŠκΈ΄λ‹€λ©΄, μ˜μ›νžˆ λŒ€κΈ°ν•  κ°€λŠ₯성이 λ†’λ‹€. μ‹€μ „μ—μ„œλŠ” 이런 μ½”λ“œλ₯Ό μ“°λ©΄μ•ˆλœλ‹€.)

//
// I2C Test
//
#include "stm32f10x.h"
#include "stm32f10x_i2c.h"

/* Private typedef -----------------------------------------------------------*/
typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;

/* Private define ------------------------------------------------------------*/
#define I2C1_SLAVE_ADDRESS7    0x30
#define I2C2_SLAVE1_ADDRESS7   0x30
#define BufferSize             4 
#define ClockSpeed             200000

I2C_InitTypeDef  I2C_InitStructure;
uint8_t I2C1_Buffer1_Tx[BufferSize] = {1,2,3,4};//, I2C1_Buffer2_Tx[BufferSize] = {5,6,7,8};
uint8_t I2C2_Buffer1_Rx[BufferSize];//, I2C2_Buffer2_Rx[BufferSize];
uint8_t Tx_Idx = 0, Rx_Idx = 0;
volatile TestStatus TransferStatus1 = FAILED;//, TransferStatus2 = FAILED;  

/* Private functions ---------------------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);

/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  RCC_Configuration();
  GPIO_Configuration();

  /* Enable I2C1 and I2C2 ----------------------------------------------------*/
  I2C_Cmd(I2C1, ENABLE);
  I2C_Cmd(I2C2, ENABLE);

  /* I2C1 configuration ------------------------------------------------------*/
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;
  I2C_Init(I2C1, &I2C_InitStructure);
  /* I2C2 configuration ------------------------------------------------------*/
  I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE1_ADDRESS7;
  I2C_Init(I2C2, &I2C_InitStructure);

    
  /*----- First transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 
  /* Send I2C2 slave Address for write */
  I2C_Send7bitAddress(I2C1, I2C2_SLAVE1_ADDRESS7, I2C_Direction_Transmitter);
  /* Test on I2C2 EV1 and clear it */
  while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED));  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); 

  /* Send data */
  while (Rx_Idx < BufferSize)
  {
    /* Send I2C1 data */
    I2C_SendData(I2C1, I2C1_Buffer1_Tx[Tx_Idx++]);
    /* Test on I2C2 EV2 and clear it */
    while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_BYTE_RECEIVED));  
    /* Store received data on I2C2 */
    I2C2_Buffer1_Rx[Rx_Idx++] = I2C_ReceiveData(I2C2);
    /* Test on I2C1 EV8 and clear it */
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); 
  }

  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);
  /* Test on I2C2 EV4 and clear it */
  while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_STOP_DETECTED)); 
  /* Clear I2C2 STOPF flag: read operation to I2C_SR1 followed by a 
     write operation to I2C_CR1 */
  (void)(I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF));
  I2C_Cmd(I2C2, ENABLE);    
 
  /* Check the corectness of written data */
  TransferStatus1 = Buffercmp(I2C1_Buffer1_Tx, I2C2_Buffer1_Rx, BufferSize);
  /* TransferStatus1 = PASSED, if the transmitted and received data
     are equal */
  /* TransferStatus1 = FAILED, if the transmitted and received data 
     are different */

  while (1)				   
  {
  }
}

/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  /* Enable peripheral clocks ------------------------------------------------*/
  /* GPIOB Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  /* I2C1 and I2C2 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 | RCC_APB1Periph_I2C2, ENABLE);
}

/**
  * @brief  Configures the different GPIO ports.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure I2C1 pins: SCL and SDA ----------------------------------------*/
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configure I2C2 pins: SCL and SDA ----------------------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
}

/**
  * @brief  Compares two buffers.
  * @param  pBuffer1, pBuffer2: buffers to be compared.
  * @param  BufferLength: buffer's length
  * @retval PASSED: pBuffer1 identical to pBuffer2
  *   FAILED: pBuffer1 differs from pBuffer2
  */
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
  while(BufferLength--)
  {
    if(*pBuffer1 != *pBuffer2)
    {
      return FAILED;
    }
    
    pBuffer1++;
    pBuffer2++;
  }

  return PASSED;  
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

레퍼런슀

⚠️ **GitHub.com Fallback** ⚠️