added i2c for same54n19a
parent
0c0d9ebe94
commit
9b39ac00ec
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
|||||||
penguin@gpenguin.13547:1645854517
|
|
@ -1,32 +1,80 @@
|
|||||||
#include "p_i2c.h"
|
#include "p_i2c.h"
|
||||||
|
#include "p_usart.h"
|
||||||
|
#include "hal_init.h"
|
||||||
|
#include "pc_board.h"
|
||||||
|
|
||||||
|
|
||||||
struct i2c_m_sync_desc p_i2c_master;
|
struct i2c_m_sync_desc p_i2c_master;
|
||||||
|
|
||||||
void p_i2c_init(void)
|
void p_i2c_init(void)
|
||||||
{
|
{
|
||||||
//// clock init
|
// clock init
|
||||||
//hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_CORE, CONF_GCLK_SERCOM3_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_CORE, CONF_GCLK_SERCOM3_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||||||
//hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_SLOW, CONF_GCLK_SERCOM3_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_SLOW, CONF_GCLK_SERCOM3_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||||||
//
|
|
||||||
//hri_mclk_set_APBBMASK_SERCOM3_bit(MCLK);
|
hri_mclk_set_APBBMASK_SERCOM3_bit(MCLK);
|
||||||
//
|
|
||||||
//i2c_m_sync_init(&p_i2c_master, I2C_MASTER_SERCOM);
|
i2c_m_sync_init(&p_i2c_master, SERCOM3);
|
||||||
//
|
|
||||||
//// port init
|
// port init
|
||||||
//gpio_set_pin_pull_mode(I2C_MASTER_SDA, GPIO_PULL_OFF);
|
gpio_set_pin_pull_mode(I2C_MASTER_SDA,
|
||||||
//gpio_set_pin_function(I2C_MASTER_SDA, I2C_MASTER_SDA_MUX);
|
// <y> Pull configuration
|
||||||
//gpio_set_pin_pull_mode(I2C_MASTER_SCL, GPIO_PULL_OFF);
|
// <id> pad_pull_config
|
||||||
//gpio_set_pin_function(I2C_MASTER_SCL, I2C_MASTER_SCL_MUX);
|
// <GPIO_PULL_OFF"> Off
|
||||||
}
|
// <GPIO_PULL_UP"> Pull-up
|
||||||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||||||
//
|
GPIO_PULL_OFF);
|
||||||
//void I2C_0_example(void)
|
|
||||||
//{
|
gpio_set_pin_function(I2C_MASTER_SDA, I2C_MASTER_SDA_MUX);
|
||||||
//struct io_descriptor *I2C_0_io;
|
|
||||||
//
|
gpio_set_pin_pull_mode(I2C_MASTER_SCL,
|
||||||
//i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io);
|
// <y> Pull configuration
|
||||||
//i2c_m_sync_enable(&I2C_0);
|
// <id> pad_pull_config
|
||||||
//i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN);
|
// <GPIO_PULL_OFF"> Off
|
||||||
//io_write(I2C_0_io, (uint8_t *)"Hello World!", 12);
|
// <GPIO_PULL_UP"> Pull-up
|
||||||
//}
|
// <GPIO_PULL_DOWN"> Pull-down
|
||||||
//
|
GPIO_PULL_OFF);
|
||||||
|
|
||||||
|
gpio_set_pin_function(I2C_MASTER_SCL, I2C_MASTER_SCL_MUX);
|
||||||
|
|
||||||
|
i2c_m_sync_enable(&p_i2c_master);
|
||||||
|
}
|
||||||
|
|
||||||
|
int p_i2c_write(const uint8_t* const data, uint16_t data_len)
|
||||||
|
{
|
||||||
|
return io_write(&p_i2c_master.io, data, data_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int p_i2c_read(uint8_t* data, uint16_t len)
|
||||||
|
{
|
||||||
|
return io_read(&p_i2c_master.io, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void p_i2c_detect(void)
|
||||||
|
{
|
||||||
|
PDEBUG(" ");
|
||||||
|
for(int ind = 0; ind < 16; ind++)
|
||||||
|
{
|
||||||
|
PDEBUG(" %02x", ind);
|
||||||
|
}
|
||||||
|
uint8_t data = 0x00;
|
||||||
|
for(int ind = 0; ind <= 119; ind++)
|
||||||
|
{
|
||||||
|
if (ind % 16 == 0)
|
||||||
|
{
|
||||||
|
PDEBUG("\r\n%02x:", ind & 0xF0);
|
||||||
|
}
|
||||||
|
i2c_m_sync_set_slaveaddr(&p_i2c_master, ind, I2C_M_SEVEN);
|
||||||
|
int ret = p_i2c_write(&data, 1);
|
||||||
|
if(ret != 1)
|
||||||
|
{
|
||||||
|
PDEBUG(" --");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PDEBUG(" %02x", ind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PDEBUG("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue