Programming Atsamd21j18a Using Atmel Studio 7 Programming C Arm Programming Need Create Ar Q43805390
I am programming an ATSAMD21J18A using Atmel Studio 7. I amprogramming in C for ARM programming. I need to create an arraythat will store the data from the temperature sensor and thendisplay it on the screen.The code below does produce a temperaturewhen running debug. Can someone please help with this? If you knowof any books or websites with help on this please share.
Code below:
#include “samd21.h”
#include
#include
#include
unsigned char* ARRAY_PORT_PINCFG0 = (unsigned char*)®_PORT_PINCFG0;
unsigned char* ARRAY_PORT_PMUX0 = (unsigned char*)®_PORT_PMUX0;
#define SLAVE_ADDR 0x4F /* 1001 111. AT30TSE758*/
//#define T_LOW_Limit_Register_Address 0x12 /* Pointer RegisterValue*/
//#define T_HIGH_Limit_Register_Address 0x13 /* Pointer RegisterValue*/
#define T_HIGH_Limit_Register_Address 0x00 /* Pointer RegisterValue*/
#define T_LOW_Limit_Register_Address 0x00
#define Temperature_Register_Address 0x00
void I2C2_init (void);
int I2C2_Byte_Read (unsigned char saddr, unsigned charPointer_Register_Value, unsigned char* data);
int I2C2_Byte_Write (unsigned char saddr, unsigned charPointer_Register_Value, unsigned char* data);
int main (void)
{
unsigned char data;
unsigned char current_temp[0];
I2C2_init();
I2C2_Byte_Read (SLAVE_ADDR, T_HIGH_Limit_Register_Address,&data);
current_temp[0] = REG_SERCOM0_I2CM_DATA;//high limit
}
void I2C2_init (void)
{
REG_PM_APBCMASK |= 0x00000004; /* SERCOM0 bus clock */
GCLK->CLKCTRL.reg = 0x4014; /* SERCOM0 core clock */
ARRAY_PORT_PINCFG0[8] |= 1; /* Allow pmux to set PA08 pinconfiguration */
ARRAY_PORT_PINCFG0[9] |= 1; /* Allow pmux to set PA08 pinconfiguration */
ARRAY_PORT_PMUX0[4] = 0x22; /* PA08 = TWI_SDA , PA09 = TWI_SCL*/
REG_SERCOM0_I2CM_CTRLA = 1; /* Reset SERCOM0 */
while (REG_SERCOM0_I2CM_CTRLA & 1) {} /* Wait for reset tocomplete */
REG_SERCOM0_I2CM_CTRLA = 0x14; /* Master mode */
REG_SERCOM0_I2CM_BAUD = 0; /* 1 MHz main clock -> ~100KHz*/
REG_SERCOM0_I2CM_CTRLA |= 2; /* Enable SERCOM0 */
REG_SERCOM0_I2CM_STATUS = 0x10; /* Force idle */
}
/*
*
* Read the Nonvolatile T_LOW Limit Register and the NonvolatileT_HIGH Limit
* Register of the AT30TSE758.
*
*/
int I2C2_Byte_Read (unsigned char saddr, unsigned charPointer_Register_Value, unsigned char* data)
{
while ( (REG_SERCOM0_I2CM_STATUS & 0x30) != 0x10); /* Waituntil idle */
REG_SERCOM0_I2CM_ADDR = SLAVE_ADDR << 1; /* Send slaveAddress */
while ( (REG_SERCOM0_I2CM_INTFLAG & 1) == 0); /* Wait untilSLAVE_ADDR sent */
REG_SERCOM0_I2CM_DATA = Pointer_Register_Value; /* Send PointerRegister Value */
while ( (REG_SERCOM0_I2CM_INTFLAG & 1) == 0); /* Wait untilPointer Register Value sent */
REG_SERCOM0_I2CM_ADDR = (saddr << 1) | 1;
while ( (REG_SERCOM0_I2CM_INTFLAG & 2) == 0); /* Wait untildata received */
*data = REG_SERCOM0_I2CM_DATA; /* Read data */
REG_SERCOM0_I2CM_CTRLB |= 0x40000; /* Generate NACK */
REG_SERCOM0_I2CM_CTRLB |= 0x30000; /* issue a stop */
return 0;
}
/* millisecond delay based on 1 MHz system clock */
void delayMs (int n)
{
int i;
for (; n > 0; n–)
for (i = 0; i < 199; i++)
{ __asm (“nop”); }
}
Here is the code and output that I have in debug. I amgetting 29 degrees from sensor. I want to store this data into anarray of size 10, then display the array with the 10temperatures.

Expert Answer
Answer to I am programming an ATSAMD21J18A using Atmel Studio 7. I am programming in C for ARM programming. I need to create an ar…
OR