mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 09:22:11 +00:00
update version to v2.1.6
This commit is contained in:
44
project/at_start_f415/examples/i2c/eeprom/inc/eeprom.h
Normal file
44
project/at_start_f415/examples/i2c/eeprom/inc/eeprom.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file eeprom.h
|
||||
* @brief i2c eeprom libray header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __EERPOM_H
|
||||
#define __EERPOM_H
|
||||
|
||||
#include "i2c_application.h"
|
||||
|
||||
#define EEPROM_BUSY_TIMEOUT 1000 /*!< eeprom busy waiting timeout */
|
||||
#define EEPROM_PAGE_SIZE 8 /*!< eeprom page size */
|
||||
#define EEPROM_I2C_ADDRESS 0xA0 /*!< eeprom i2c address */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EE_MODE_POLL = 0x01, /*!< polling communication */
|
||||
EE_MODE_INT = 0x02, /*!< interrupt communication */
|
||||
EE_MODE_DMA = 0x03, /*!< dma communication */
|
||||
} eeprom_mode_type;
|
||||
|
||||
i2c_status_type eeprom_write_buffer(i2c_handle_type* hi2c, eeprom_mode_type mode, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type eeprom_read_buffer (i2c_handle_type* hi2c, eeprom_mode_type mode, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
|
||||
#endif
|
||||
@@ -211,6 +211,18 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\eeprom.c</PathWithFileName>
|
||||
<FilenameWithoutPath>eeprom.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
@@ -221,7 +233,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileNumber>5</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -233,7 +245,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>5</FileNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -253,7 +265,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -265,7 +277,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -277,7 +289,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -289,7 +301,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -301,7 +313,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -313,7 +325,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -333,7 +345,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -345,7 +357,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileType>2</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -365,7 +377,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
||||
@@ -397,6 +397,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\main.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>eeprom.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\eeprom.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -484,4 +489,14 @@
|
||||
<files/>
|
||||
</RTE>
|
||||
|
||||
<LayerInfo>
|
||||
<Layers>
|
||||
<Layer>
|
||||
<LayName><Project Info></LayName>
|
||||
<LayTarg>0</LayTarg>
|
||||
<LayPrjMark>1</LayPrjMark>
|
||||
</Layer>
|
||||
</Layers>
|
||||
</LayerInfo>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
this demo is based on the at-start board and AT32-Comm-EV, in this demo, use hardware i2c1
|
||||
write or read data based on the memory device. if the communication is
|
||||
this demo is based on the at-start board and AT32-Comm-EV, in this demo, use hardware i2c2
|
||||
write or read data based on the eeprom device. if the communication is
|
||||
successful, led3 will turn on, if the communication fails, led2 will keep flashing.
|
||||
|
||||
attention:
|
||||
|
||||
330
project/at_start_f415/examples/i2c/eeprom/src/eeprom.c
Normal file
330
project/at_start_f415/examples/i2c/eeprom/src/eeprom.c
Normal file
@@ -0,0 +1,330 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file eeprom.c
|
||||
* @brief the driver library of the i2c eeprom
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "eeprom.h"
|
||||
|
||||
/**
|
||||
* @brief check if the eeprom device is ready
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: eeprom address.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type eeprom_ready_check(i2c_handle_type* hi2c, uint16_t address, uint32_t timeout)
|
||||
{
|
||||
/* wait for the busy flag to be reset */
|
||||
if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
|
||||
{
|
||||
return I2C_ERR_STEP_1;
|
||||
}
|
||||
|
||||
/* ack acts on the current byte */
|
||||
i2c_master_receive_ack_set(hi2c->i2cx, I2C_MASTER_ACK_CURRENT);
|
||||
|
||||
/* generate start condtion */
|
||||
i2c_start_generate(hi2c->i2cx);
|
||||
|
||||
/* wait for the start flag to be set */
|
||||
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
|
||||
{
|
||||
/* generate stop condtion */
|
||||
i2c_stop_generate(hi2c->i2cx);
|
||||
|
||||
return I2C_ERR_STEP_2;
|
||||
}
|
||||
|
||||
/* send slave address */
|
||||
i2c_7bit_address_send(hi2c->i2cx, address, I2C_DIRECTION_TRANSMIT);
|
||||
|
||||
/* wait for the addr7 flag to be set */
|
||||
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
|
||||
{
|
||||
return I2C_ERR_STEP_3;
|
||||
}
|
||||
|
||||
/* clear addr flag */
|
||||
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
|
||||
|
||||
/* generate stop condtion */
|
||||
i2c_stop_generate(hi2c->i2cx);
|
||||
|
||||
/* wait for the busy flag to be reset */
|
||||
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
|
||||
{
|
||||
return I2C_ERR_STEP_4;
|
||||
}
|
||||
|
||||
return I2C_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief wait for eeprom device to be ready
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: eeprom address.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type eeprom_ready_wait(i2c_handle_type* hi2c, uint16_t address, uint32_t timeout)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
|
||||
for(i = 0; i < EEPROM_BUSY_TIMEOUT; i++)
|
||||
{
|
||||
if(eeprom_ready_check(hi2c, address, timeout) == I2C_OK)
|
||||
{
|
||||
return I2C_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return I2C_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief write data to the eeprom page.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param mode: transfer mode.
|
||||
* this parameter can be one of the following values:
|
||||
* - EE_MODE_POLL: poll mode
|
||||
* - EE_MODE_INT: interrupt mode
|
||||
* - EE_MODE_DMA: dma mode
|
||||
* @param mem_address_width: memory address width.
|
||||
* this parameter can be one of the following values:
|
||||
* - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit
|
||||
* - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit
|
||||
* @param address: eeprom address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type eeprom_write_page(i2c_handle_type* hi2c, eeprom_mode_type mode, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
i2c_status_type status;
|
||||
|
||||
/* write data to eeprom */
|
||||
if(mode == EE_MODE_POLL)
|
||||
{
|
||||
return i2c_memory_write(hi2c, mem_address_width, address, mem_address, pdata, size, timeout);
|
||||
}
|
||||
else if(mode == EE_MODE_INT)
|
||||
{
|
||||
status = i2c_memory_write_int(hi2c, mem_address_width, address, mem_address, pdata, size, timeout);
|
||||
|
||||
if(status != I2C_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* wait for the communication to end */
|
||||
return i2c_wait_end(hi2c, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = i2c_memory_write_dma(hi2c, mem_address_width, address, mem_address, pdata, size, timeout);
|
||||
|
||||
if(status != I2C_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* wait for the communication to end */
|
||||
return i2c_wait_end(hi2c, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief read data from eeprom.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param mode: transfer mode.
|
||||
* this parameter can be one of the following values:
|
||||
* - EE_MODE_POLL: poll mode
|
||||
* - EE_MODE_INT: interrupt mode
|
||||
* - EE_MODE_DMA: dma mode
|
||||
* @param mem_address_width: memory address width.
|
||||
* this parameter can be one of the following values:
|
||||
* - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit
|
||||
* - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit
|
||||
* @param address: eeprom address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type eeprom_read_buffer(i2c_handle_type* hi2c, eeprom_mode_type mode, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
i2c_status_type status;
|
||||
|
||||
/* write data to eeprom */
|
||||
if(mode == EE_MODE_POLL)
|
||||
{
|
||||
return i2c_memory_read(hi2c, mem_address_width, address, mem_address, pdata, size, timeout);
|
||||
}
|
||||
else if(mode == EE_MODE_INT)
|
||||
{
|
||||
status = i2c_memory_read_int(hi2c, mem_address_width, address, mem_address, pdata, size, timeout);
|
||||
|
||||
if(status != I2C_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* wait for the communication to end */
|
||||
return i2c_wait_end(hi2c, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = i2c_memory_read_dma(hi2c, mem_address_width, address, mem_address, pdata, size, timeout);
|
||||
|
||||
if(status != I2C_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* wait for the communication to end */
|
||||
return i2c_wait_end(hi2c, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief write data to the eeprom device.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param mode: transfer mode.
|
||||
* this parameter can be one of the following values:
|
||||
* - EE_MODE_POLL: poll mode
|
||||
* - EE_MODE_INT: interrupt mode
|
||||
* - EE_MODE_DMA: dma mode
|
||||
* @param mem_address_width: memory address width.
|
||||
* this parameter can be one of the following values:
|
||||
* - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit
|
||||
* - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit
|
||||
* @param address: eeprom address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type eeprom_write_buffer(i2c_handle_type* hi2c, eeprom_mode_type mode, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
uint16_t page_number = 0;
|
||||
uint16_t page_last = 0;
|
||||
uint16_t single_write = 0;
|
||||
uint16_t write_address = 0;
|
||||
i2c_status_type status;
|
||||
|
||||
/* calculate the number of data programred for the first time, and the subsequent program address will be aligned */
|
||||
single_write = mem_address / EEPROM_PAGE_SIZE * EEPROM_PAGE_SIZE + EEPROM_PAGE_SIZE - mem_address;
|
||||
|
||||
/* first program address */
|
||||
write_address = mem_address;
|
||||
|
||||
if (size < single_write)
|
||||
{
|
||||
single_write = size;
|
||||
}
|
||||
|
||||
/* write data to eeprom */
|
||||
status = eeprom_write_page(hi2c, mode, mem_address_width, address, write_address, pdata, single_write, timeout);
|
||||
|
||||
if(status != I2C_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* wait for eeprom device to be ready */
|
||||
if(eeprom_ready_wait(hi2c, address, timeout) != I2C_OK)
|
||||
{
|
||||
return I2C_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
/* address increase */
|
||||
write_address += single_write;
|
||||
|
||||
/* subtract the number of data programed for the first time */
|
||||
size -= single_write;
|
||||
|
||||
/* pointer increase */
|
||||
pdata += single_write;
|
||||
|
||||
/* if the remaining quantity is 0, it means the program is complete */
|
||||
if (size == 0)
|
||||
{
|
||||
return I2C_OK;
|
||||
}
|
||||
|
||||
/* calculate the number of bytes in less than one page */
|
||||
page_last = size % EEPROM_PAGE_SIZE;
|
||||
|
||||
/* calculate the number of full page */
|
||||
page_number = size / EEPROM_PAGE_SIZE;
|
||||
|
||||
/* program an integer number of pages of data */
|
||||
while(page_number > 0)
|
||||
{
|
||||
/* write data to eeprom */
|
||||
status = eeprom_write_page(hi2c, mode, mem_address_width, address, write_address, pdata, EEPROM_PAGE_SIZE, timeout);
|
||||
|
||||
if(status != I2C_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* wait for eeprom device to be ready */
|
||||
if(eeprom_ready_wait(hi2c, address, timeout) != I2C_OK)
|
||||
{
|
||||
return I2C_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
/* page number subtract */
|
||||
page_number--;
|
||||
|
||||
/* address increase */
|
||||
write_address += EEPROM_PAGE_SIZE;
|
||||
|
||||
/* pointer increase */
|
||||
pdata += EEPROM_PAGE_SIZE;
|
||||
}
|
||||
|
||||
/* programring less than one page of data */
|
||||
if (page_last)
|
||||
{
|
||||
/* write data to eeprom */
|
||||
status = eeprom_write_page(hi2c, mode, mem_address_width, address, write_address, pdata, page_last, timeout);
|
||||
|
||||
if(status != I2C_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* wait for eeprom device to be ready */
|
||||
if(eeprom_ready_wait(hi2c, address, timeout) != I2C_OK)
|
||||
{
|
||||
return I2C_ERR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return I2C_OK;
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "at32f415_board.h"
|
||||
#include "at32f415_clock.h"
|
||||
#include "i2c_application.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
/** @addtogroup AT32F415_periph_examples
|
||||
* @{
|
||||
@@ -60,11 +60,11 @@
|
||||
#define I2Cx_EVT_IRQn I2C2_EVT_IRQn
|
||||
#define I2Cx_ERR_IRQn I2C2_ERR_IRQn
|
||||
|
||||
#define BUF_SIZE 8
|
||||
#define BUF_SIZE 12
|
||||
|
||||
uint8_t tx_buf1[BUF_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||
uint8_t tx_buf2[BUF_SIZE] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80};
|
||||
uint8_t tx_buf3[BUF_SIZE] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
|
||||
uint8_t tx_buf1[BUF_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C};
|
||||
uint8_t tx_buf2[BUF_SIZE] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xB0, 0xC0};
|
||||
uint8_t tx_buf3[BUF_SIZE] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC};
|
||||
uint8_t rx_buf1[BUF_SIZE] = {0};
|
||||
uint8_t rx_buf2[BUF_SIZE] = {0};
|
||||
uint8_t rx_buf3[BUF_SIZE] = {0};
|
||||
@@ -205,72 +205,55 @@ int main(void)
|
||||
{
|
||||
}
|
||||
|
||||
/* write data to memory device */
|
||||
if((i2c_status = i2c_memory_write(&hi2cx, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, tx_buf1, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
/* write data to eeprom device */
|
||||
if((i2c_status = eeprom_write_buffer(&hi2cx, EE_MODE_POLL, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, tx_buf1, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
delay_ms(1);
|
||||
|
||||
/* read data from eeprom device */
|
||||
if((i2c_status = eeprom_read_buffer(&hi2cx, EE_MODE_POLL, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, rx_buf1, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
delay_ms(5);
|
||||
|
||||
/* read data from memory device */
|
||||
if((i2c_status = i2c_memory_read(&hi2cx, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, rx_buf1, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
|
||||
|
||||
/* write data to eeprom device */
|
||||
if((i2c_status = eeprom_write_buffer(&hi2cx, EE_MODE_INT, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, tx_buf2, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
/* write data to memory device */
|
||||
if((i2c_status = i2c_memory_write_int(&hi2cx, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, tx_buf2, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
delay_ms(1);
|
||||
|
||||
/* wait for the communication to end */
|
||||
if(i2c_wait_end(&hi2cx, I2C_TIMEOUT) != I2C_OK)
|
||||
/* read data from eeprom device */
|
||||
if((i2c_status = eeprom_read_buffer(&hi2cx, EE_MODE_INT, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, rx_buf2, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
delay_ms(5);
|
||||
|
||||
/* read data from memory device */
|
||||
if((i2c_status = i2c_memory_read_int(&hi2cx, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, rx_buf2, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
|
||||
|
||||
/* write data to eeprom device */
|
||||
if((i2c_status = eeprom_write_buffer(&hi2cx, EE_MODE_DMA, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, tx_buf3, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
/* wait for the communication to end */
|
||||
if(i2c_wait_end(&hi2cx, I2C_TIMEOUT) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
/* write data to memory device */
|
||||
if((i2c_status = i2c_memory_write_dma(&hi2cx, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, tx_buf3, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
/* wait for the communication to end */
|
||||
if(i2c_wait_end(&hi2cx, I2C_TIMEOUT) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
delay_ms(5);
|
||||
|
||||
/* read data from memory device */
|
||||
if((i2c_status = i2c_memory_read_dma(&hi2cx, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, rx_buf3, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
/* wait for the communication to end */
|
||||
if(i2c_wait_end(&hi2cx, I2C_TIMEOUT) != I2C_OK)
|
||||
delay_ms(1);
|
||||
|
||||
/* read data from eeprom device */
|
||||
if((i2c_status = eeprom_read_buffer(&hi2cx, EE_MODE_DMA, I2C_MEM_ADDR_WIDIH_8, I2Cx_ADDRESS, 0x00, rx_buf3, BUF_SIZE, I2C_TIMEOUT)) != I2C_OK)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
|
||||
if((buffer_compare(tx_buf1, rx_buf1, BUF_SIZE) == 0) &&
|
||||
(buffer_compare(tx_buf2, rx_buf2, BUF_SIZE) == 0) &&
|
||||
(buffer_compare(tx_buf3, rx_buf3, BUF_SIZE) == 0))
|
||||
@@ -281,7 +264,6 @@ int main(void)
|
||||
{
|
||||
error_handler(i2c_status);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user