#include "stddef.h"
#include "em_system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "i2cspm.h"
#include "si7013.h"
#include "sl_sleeptimer.h"
#include "graphics.h"
#include "em_adc.h"
#include "bspconfig.h"
uint8_t com1[1] = {0xE3};
uint8_t i2c_rxBuffer[3];
int main(void)
{
I2C_TransferSeq_TypeDef i2cTransfer;
I2C_TransferReturn_TypeDef result;
I2CSPM_Init_TypeDef i2cInit = I2CSPM_INIT_DEFAULT;
/* Chip errata */
CHIP_Init();
// Enabling clock to the I2C, GPIO, LE
CMU_ClockEnable(cmuClock_I2C0, true);
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_HFLE, true);
// Starting LFXO and waiting until it is stable
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
I2CSPM_Init(&i2cInit);
// In order to enable the I2C0_SCL function in PC10 you need to use ROUTE 14
// In order to enable the I2C0_SDA function in PC11 you need to use ROUTE 16
//Also note that there's a GPIO pin PD15 that need to be set to high in order to route the signals to the sensor,
// Using PC10 (SCL) and PC11 (SDA)
GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAndPullUp, 1);
GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAndPullUp, 1);
//Si7021 switch on
GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 1);
// Enable pins at location 15 as specified in datasheet
I2C0->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SDALOC_MASK)) | I2C_ROUTELOC0_SDALOC_LOC16;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SCLLOC_MASK)) | I2C_ROUTELOC0_SCLLOC_LOC14;
i2cTransfer.flags=I2C_FLAG_WRITE_READ;
i2cTransfer.addr=0x80;//address with write
i2cTransfer.buf[0].data=com1[0]; // Measure Temperature, Hold Master Mode
i2cTransfer.buf[0].len=2; //2 bytes length
i2cTransfer.buf[1].data=i2c_rxBuffer;
i2cTransfer.buf[1].len=3; //LS MS checksum
while(1)
{
result=I2C_TransferInit(I2C0,&i2cTransfer);
// Sending data
while (result == i2cTransferInProgress)
{
result = I2C_Transfer(I2C0);
}
}
}
#include "stddef.h"
#include "em_system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "i2cspm.h"
#include "si7013.h"
#include "sl_sleeptimer.h"
#include "graphics.h"
#include "em_adc.h"
#include "bspconfig.h"
uint8_t com1[1] = {0xE3};
uint8_t i2c_rxBuffer[3];
int main(void)
{
I2C_TransferSeq_TypeDef i2cTransfer;
I2C_TransferReturn_TypeDef result;
I2CSPM_Init_TypeDef i2cInit = I2CSPM_INIT_DEFAULT;
/* Chip errata */
CHIP_Init();
// Enabling clock to the I2C, GPIO, LE
CMU_ClockEnable(cmuClock_I2C0, true);
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_HFLE, true);
// Starting LFXO and waiting until it is stable
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
I2CSPM_Init(&i2cInit);
// In order to enable the I2C0_SCL function in PC10 you need to use ROUTE 14
// In order to enable the I2C0_SDA function in PC11 you need to use ROUTE 16
//Also note that there's a GPIO pin PD15 that need to be set to high in order to route the signals to the sensor,
// Using PC10 (SCL) and PC11 (SDA)
GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAndPullUp, 1);
GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAndPullUp, 1);
// GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAnd, 1);
// GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAnd, 1);
//Si7021 switch on
GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 1);
// Enable pins at location 15 as specified in datasheet
I2C0->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SDALOC_MASK)) | I2C_ROUTELOC0_SDALOC_LOC16;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SCLLOC_MASK)) | I2C_ROUTELOC0_SCLLOC_LOC14;
i2cTransfer.flags=I2C_FLAG_WRITE_READ;
i2cTransfer.addr=0x80;//address with write
i2cTransfer.buf[0].data=&com1[0]; // Measure Temperature, Hold Master Mode
i2cTransfer.buf[0].len=1; //1 byte E3 measure temp command
i2cTransfer.buf[1].data=i2c_rxBuffer;
i2cTransfer.buf[1].len=3; //LS MS checksum
while(1)
{
result=I2C_TransferInit(I2C0,&i2cTransfer);
// Sending data
while (result == i2cTransferInProgress)
{
result = I2C_Transfer(I2C0);
}
}
}
#include "stddef.h"
#include "em_system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "i2cspm.h"
#include "si7013.h"
#include "sl_sleeptimer.h"
#include "graphics.h"
#include "em_adc.h"
#include "bspconfig.h"
uint8_t com1[1] = {0xE3};
uint8_t i2c_rxBuffer[3];
int main(void)
{
I2C_TransferSeq_TypeDef i2cTransfer;
I2C_TransferReturn_TypeDef result;
I2CSPM_Init_TypeDef i2cInit = I2CSPM_INIT_DEFAULT;
/* Chip errata */
CHIP_Init();
// Enabling clock to the I2C, GPIO, LE
CMU_ClockEnable(cmuClock_I2C0, true);
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_HFLE, true);
// Starting LFXO and waiting until it is stable
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
I2CSPM_Init(&i2cInit);
// In order to enable the I2C0_SCL function in PC10 you need to use ROUTE 14
// In order to enable the I2C0_SDA function in PC11 you need to use ROUTE 16
//Also note that there's a GPIO pin PD15 that need to be set to high in order to route the signals to the sensor,
// Using PC10 (SCL) and PC11 (SDA)
GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAndPullUp, 1);
GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAndPullUp, 1);
// GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAnd, 1);
// GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAnd, 1);
//Si7021 switch on
GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 1);
// Enable pins at location 15 as specified in datasheet
I2C0->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SDALOC_MASK)) | I2C_ROUTELOC0_SDALOC_LOC16;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SCLLOC_MASK)) | I2C_ROUTELOC0_SCLLOC_LOC14;
i2cTransfer.flags=I2C_FLAG_WRITE_READ;
i2cTransfer.addr=0x80;//address with write
i2cTransfer.buf[0].data=&com1[0]; // Measure Temperature, Hold Master Mode
i2cTransfer.buf[0].len=1; //1 byte E3 measure temp command
i2cTransfer.buf[1].data=i2c_rxBuffer;
i2cTransfer.buf[1].len=3; //LS MS checksum
while(1)
{
result=I2C_TransferInit(I2C0,&i2cTransfer);
// Sending data
while (result == i2cTransferInProgress)
{
result = I2C_Transfer(I2C0);
}
}
}
#include "stddef.h"
#include "em_system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "i2cspm.h"
#include "si7013.h"
#include "sl_sleeptimer.h"
#include "graphics.h"
#include "em_adc.h"
#include "bspconfig.h"
uint8_t com1[1] = {0xE3};
uint8_t i2c_rxBuffer[3];
int main(void)
{
I2C_TransferSeq_TypeDef i2cTransfer;
I2C_TransferReturn_TypeDef result;
I2CSPM_Init_TypeDef i2cInit = I2CSPM_INIT_DEFAULT;
/* Chip errata */
CHIP_Init();
// Enabling clock to the I2C, GPIO, LE
CMU_ClockEnable(cmuClock_I2C0, true);
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_HFLE, true);
// Starting LFXO and waiting until it is stable
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
I2CSPM_Init(&i2cInit);
// In order to enable the I2C0_SCL function in PC10 you need to use ROUTE 14
// In order to enable the I2C0_SDA function in PC11 you need to use ROUTE 16
//Also note that there's a GPIO pin PD15 that need to be set to high in order to route the signals to the sensor,
// Using PC10 (SCL) and PC11 (SDA)
GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAndPullUp, 1);
GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAndPullUp, 1);
// GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAnd, 1);
// GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAnd, 1);
//Si7021 switch on
GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 1);
// Enable pins at location 15 as specified in datasheet
I2C0->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SDALOC_MASK)) | I2C_ROUTELOC0_SDALOC_LOC16;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SCLLOC_MASK)) | I2C_ROUTELOC0_SCLLOC_LOC14;
i2cTransfer.flags=I2C_FLAG_WRITE_READ;
i2cTransfer.addr=0x80;//address with write
i2cTransfer.buf[0].data=&com1[0]; // Measure Temperature, Hold Master Mode
i2cTransfer.buf[0].len=1; //1 byte E3 measure temp command
i2cTransfer.buf[1].data=i2c_rxBuffer;
i2cTransfer.buf[1].len=3; //LS MS checksum
while(1)
{
result=I2C_TransferInit(I2C0,&i2cTransfer);
// Sending data
while (result == i2cTransferInProgress)
{
result = I2C_Transfer(I2C0);
}
}
}
#include "em_usart.h"
#include "em_ldma.h"
/////////////////
#include "stddef.h"
#include "em_system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "i2cspm.h"
#include "si7013.h"
#include "sl_sleeptimer.h"
#include "graphics.h"
#include "em_adc.h"
#include "bspconfig.h"
uint8_t com1[1] = {0xE3}; //measure command
uint8_t com2[4] = {0x03,0x0F,0xFF,0xF0}; //spi data sending
uint8_t i2c_rxBuffer[3]; //[0]-MS [1]-LS [2]-CheckSum
void initUSART1 (void)
{
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_USART1, true);
// Configure GPIO mode
GPIO_PinModeSet(gpioPortC, 8, gpioModePushPull, 0); // US1_CLK is push pull
GPIO_PinModeSet(gpioPortC, 9, gpioModePushPull, 1); // US1_CS is push pull
GPIO_PinModeSet(gpioPortC, 6, gpioModePushPull, 1); // US1_TX (MOSI) is push pull
GPIO_PinModeSet(gpioPortC, 7, gpioModeInput, 1); // US1_RX (MISO) is input
GPIO_PinModeSet(gpioPortF, 7, gpioModeInput, 1); // delay gpio
// Start with default config, then modify as necessary
USART_InitSync_TypeDef config = USART_INITSYNC_DEFAULT;
config.master = true; // master mode
config.baudrate = 1000000; // CLK freq is 1 MHz
config.autoCsEnable = true; // CS pin controlled by hardware, not firmware
config.clockMode = usartClockMode0; // clock idle low, sample on rising/first edge
config.autoCsEnable = true; // CS pin controlled by firmware
config.msbf = true; // send MSB first
config.enable = usartDisable; // Make sure to keep USART disabled until it's all set up
USART_InitSync(USART1, &config);
// Set USART pin locations
USART1->ROUTELOC0 = (USART_ROUTELOC0_CLKLOC_LOC11) | // US1_CLK on location 11 = PC8 per datasheet section 6.4 = EXP Header pin 8
(USART_ROUTELOC0_CSLOC_LOC11) | // US1_CS on location 11 = PC9 per datasheet section 6.4 = EXP Header pin 10
(USART_ROUTELOC0_TXLOC_LOC11) | // US1_TX (MOSI) on location 11 = PC6 per datasheet section 6.4 = EXP Header pin 4
(USART_ROUTELOC0_RXLOC_LOC11); // US1_RX (MISO) on location 11 = PC7 per datasheet section 6.4 = EXP Header pin 6
// Enable USART pins
USART1->ROUTEPEN = USART_ROUTEPEN_CLKPEN | USART_ROUTEPEN_CSPEN | USART_ROUTEPEN_TXPEN | USART_ROUTEPEN_RXPEN;
// Enable USART1
USART_Enable(USART1, usartEnable);
////////////////////////////////////////////
//UART INITLIZATION
USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
// Enable oscillator to GPIO and USART0 modules
CMU_ClockEnable(cmuClock_USART0, true);
// set pin modes for UART TX and RX pins
GPIO_PinModeSet(gpioPortA, 1, gpioModeInput, 0);
GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 1);
// Initialize USART asynchronous mode and route pins
USART_InitAsync(USART0, &init);
USART0->ROUTELOC0 = USART_ROUTELOC0_RXLOC_LOC0 | USART_ROUTELOC0_TXLOC_LOC0;
USART0->ROUTEPEN |= USART_ROUTEPEN_TXPEN | USART_ROUTEPEN_RXPEN;
}//end usart init
int main(void)
{
I2C_TransferSeq_TypeDef i2cTransfer;
I2C_TransferReturn_TypeDef result;
I2CSPM_Init_TypeDef i2cInit = I2CSPM_INIT_DEFAULT;
/* Chip errata */
CHIP_Init();
initUSART1();
// Enabling clock to the I2C, GPIO, LE
CMU_ClockEnable(cmuClock_I2C0, true);
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_HFLE, true);
// Starting LFXO and waiting until it is stable
CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
I2CSPM_Init(&i2cInit);
// In order to enable the I2C0_SCL function in PC10 you need to use ROUTE 14
// In order to enable the I2C0_SDA function in PC11 you need to use ROUTE 16
//Also note that there's a GPIO pin PD15 that need to be set to high in order to route the signals to the sensor,
// Using PC10 (SCL) and PC11 (SDA)
GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAndPullUp, 1);
GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAndPullUp, 1);
// GPIO_PinModeSet(gpioPortC, 10, gpioModeWiredAnd, 1);
// GPIO_PinModeSet(gpioPortC, 11, gpioModeWiredAnd, 1);
//Si7021 switch on
GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 1);
// Enable pins at location 15 as specified in datasheet
I2C0->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SDALOC_MASK)) | I2C_ROUTELOC0_SDALOC_LOC16;
I2C0->ROUTELOC0 = (I2C0->ROUTELOC0 & (~_I2C_ROUTELOC0_SCLLOC_MASK)) | I2C_ROUTELOC0_SCLLOC_LOC14;
i2cTransfer.flags=I2C_FLAG_WRITE_READ;
i2cTransfer.addr=0x80;//address with write
i2cTransfer.buf[0].data=&com1[0]; // Measure Temperature, Hold Master Mode
i2cTransfer.buf[0].len=1; //1 byte E3 measure temp command
i2cTransfer.buf[1].data=i2c_rxBuffer;
i2cTransfer.buf[1].len=3; //LS MS checksum
while(1)
{
result=I2C_TransferInit(I2C0,&i2cTransfer);
// Sending data
while (result == i2cTransferInProgress)
{
result = I2C_Transfer(I2C0);
}
//When sending data ends
//SPI sending data
USART_SpiTransfer(USART1,i2c_rxBuffer[0]);
USART_SpiTransfer(USART1,i2c_rxBuffer[1]);
USART_SpiTransfer(USART1,i2c_rxBuffer[2]);
//send UART
USART_Tx(USART0, 0x61);
USART_Tx(USART0, i2c_rxBuffer[0]);
USART_Tx(USART0, i2c_rxBuffer[1]);
USART_Tx(USART0, i2c_rxBuffer[2]);
USART_Tx(USART0, '\n');
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?