7847c5e98d
* Microchip SAM MCU BSP update and add ethernet driver 1. Update Microchip SAM MCU BSP, add I2C, GMAC, ADC driver support. 2. Add ethernet driver support of SAM MCU for RT-Thread. * Add GMAC and I2C driver support 1. Update MCU BSP to support I2C/ADC/GMAC peripherals. 2. Add I2C and ethernet driver and LWIP support. 3. Update serial driver. * Add I2C driver and move some files to the common folder 1. Add I2C driver. 2. Move the same drivers and demo code to same folder to reduce duplicated code.
66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
/*
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Email Notes
|
|
* 2022-04-16 Kevin.Liu kevin.liu.mchp@gmail.com First Release
|
|
*/
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <atmel_start.h>
|
|
|
|
#include "i2c_demo.h"
|
|
|
|
#ifdef SAM_I2C_EXAMPLE
|
|
|
|
#define I2C_AT24MAC_PGMAXSZ (16+1)
|
|
#define CONF_AT24MAC_ADDRESS 0x57
|
|
|
|
/**
|
|
* @brief Call this function will run I2C test code.
|
|
*
|
|
* @note Test code will try to read/write external EEPROM.
|
|
*
|
|
* @param None.
|
|
*
|
|
* @return RT_OK or -RT_ERROR.
|
|
*/
|
|
|
|
rt_err_t i2c_demo_run(void)
|
|
{
|
|
rt_uint8_t addr = 0x20;
|
|
rt_int32_t len;
|
|
rt_uint8_t i2ctx[I2C_AT24MAC_PGMAXSZ];
|
|
rt_uint8_t i2crx[I2C_AT24MAC_PGMAXSZ];
|
|
|
|
for (len = 1; len < I2C_AT24MAC_PGMAXSZ; len++)
|
|
{
|
|
i2ctx[len] = (rt_uint8_t)(len + 0x20);
|
|
}
|
|
|
|
/* enable I2C master and set slave address before use I2C driver module */
|
|
i2c_m_sync_enable(&I2C_0);
|
|
i2c_m_sync_set_slaveaddr(&I2C_0, CONF_AT24MAC_ADDRESS, I2C_M_SEVEN);
|
|
|
|
/* write 16bytes data to address 0x20 - I2C slave address + random address + write data[0]...[n] */
|
|
i2ctx[0] = addr; /* Refer to AT24MAC data sheet, first byte is page address. */
|
|
io_write(&(I2C_0.io), i2ctx, I2C_AT24MAC_PGMAXSZ);
|
|
|
|
/* Refer to data sheet, for random read, should send read address first. */
|
|
io_write(&(I2C_0.io), &addr, 1);
|
|
|
|
/* Then start I2C read after send I2C slave address first */
|
|
io_read(&(I2C_0.io), &i2crx[1], 16);
|
|
#ifndef RT_USING_FINSH
|
|
rt_kprintf("i2crx[0]=0x%02X i2crx[15]=0x%02X\r\n", i2crx[0], i2crx[15]);
|
|
#endif
|
|
|
|
return RT_EOK;
|
|
}
|
|
#endif
|
|
|
|
/*@}*/
|