I2C receiving issue in xmc1300

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
smart
Level 1
Level 1
10 sign-ins First like given 5 replies posted

This is code for TSSOP this code is  for XMC1300 driver card. TSSOP38
1. What is the cause of getting the issue ?
2. What is correct code for recieving the data byte ?

/*This is code to read the values from pressure sensor(BMP280)
The SDA and SCL pins are pull up using 4.7k ohms
channel = channel 0 
*/
/*********************************************************************************************************************
  * HEADER FILES
 ********************************************************************************************************************/
#include <XMC1300.h>
#include <xmc_i2c.h>
#include <xmc_gpio.h>
#include <string.h>
#include <stdint.h>
#include <xmc_scu.h>
#include "xmc_common.h"

/*********************************************************************************************************************
  * MACROS
*********************************************************************************************************************/
#define I2C_CH_NUM     	XMC_I2C0_CH0
#define SDA_PIN 	P2_1
#define SCL_PIN 	P2_0
#define LED1	 	P0_4
#define SLAVE_ID	(0xEC)
#define RegisterAddress 0xD0

/*********************************************************************************************************************
  * DATA STRUCTURES
*********************************************************************************************************************/
/* IIC configuration */
XMC_I2C_CH_CONFIG_t i2c_cfg =
{
  .baudrate = 400000U,
  .address = EEPROM_I2C_ADR
};

/* IIC SDA and SCL Pins */
XMC_GPIO_CONFIG_t i2c_sda =
{
  .mode =    XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT6,
  .output_level=  XMC_GPIO_OUTPUT_LEVEL_HIGH,
};

XMC_GPIO_CONFIG_t i2c_scl =
{
  .mode =	XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT7,
  .output_level=  XMC_GPIO_OUTPUT_LEVEL_HIGH,
};

/* GPIO LED pin configuration */
XMC_GPIO_CONFIG_t LED_pin_config =
{
  .mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
};

XMC_USIC_CH_t *i2c = I2C_CH_NUM;
XMC_SCU_CLOCK_CONFIG_t clock_config;

/*********************************************************************************************************************
  * GLOBAL VARIABLES
*********************************************************************************************************************/
uint8_t ReceivedData[3];

/*********************************************************************************************************************
  * APPLICATION CODE
*********************************************************************************************************************/
uint8_t RecieveByte(void)
{
	uint16_t Data[3];
	/* Read received data */
	for (volatile uint8_t gu8Index = 0; gu8Index <3; gu8Index++){
		Data[gu8Index] =  XMC_USIC_CH_RXFIFO_GetData(I2C_CH_NUM);
	}
return 0;
}

void Init_I2C(void) {
	/* Configure Clock */
	clock_config.pclk_src=XMC_SCU_CLOCK_PCLKSRC_MCLK; /*PCLK = MCLK*/
	clock_config.rtc_src=XMC_SCU_CLOCK_RTCCLKSRC_DCO2;
	clock_config.fdiv = 0; /**< Fractional divider */
	clock_config.idiv = 1; /**MCLK = 32MHz */

	XMC_SCU_CLOCK_Init(&clock_config);
	for (volatile uint8_t gu8Index = 0; gu8Index < 10; gu8Index++);

	/* Configure LED1 */
	XMC_GPIO_Init(XMC_GPIO_PORT0, 4, &LED_pin_config);

	XMC_I2C_CH_Init(I2C_CH_NUM, &i2c_cfg);
	XMC_I2C_CH_Start(i2c);

	/* I2C initialization sequence*/
	XMC_I2C_CH_SetInputSource(i2c, XMC_I2C_CH_INPUT_SDA, 5); //DX0 -> DOUT0 USIC0_C0_DX0_P1_5 P1_5_AF_U0C0_DOUT0
	XMC_I2C_CH_SetInputSource(i2c, XMC_I2C_CH_INPUT_SCL, 4); //DX1 -> SCLKOUT  USIC0_C1_DX1_P1_4 P1_4_AF_U0C1_SCLKOUT
	// 8 entries for TxFIFO from point 0, LIMIT=1
	XMC_USIC_CH_TXFIFO_Configure(I2C_CH_NUM, 0,XMC_USIC_CH_FIFO_SIZE_8WORDS, 1);
	// 8 entries for RxFIFO from point 16, LIMIT=7 (SRBI is set if all 8*data has been received)
	XMC_USIC_CH_RXFIFO_Configure(I2C_CH_NUM, 8,XMC_USIC_CH_FIFO_SIZE_8WORDS, 7);

	/* I2C port pin configuration*/
	XMC_GPIO_Init(SDA_PIN, &i2c_sda);
	XMC_GPIO_Init(SCL_PIN, &i2c_scl);
}

int main(void) {
	uint8_t ReceivedData1[4];
	Init_I2C();
	 /* Send START conditon */
	XMC_I2C_CH_MasterStart(I2C_CH_NUM,SLAVE_ID, XMC_I2C_CH_CMD_WRITE);

	/* Wait for acknowledge and reset status */
	 while((XMC_I2C_CH_GetStatusFlag(I2C_CH_NUM) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 0U)
	{
            /* wait for ACK from slave */
	}
	XMC_I2C_CH_ClearStatusFlag(I2C_CH_NUM,(uint32_t)XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);

	/* Transmit next command from I2C master to I2C slave */
	XMC_I2C_CH_MasterTransmit(I2C_CH_NUM, RegisterAddress);
        /* Wait for acknowledge and reset status */
        while((XMC_I2C_CH_GetStatusFlag(I2C_CH_NUM) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 0U)
        {
            /* wait for ACK from slave */
        }

        XMC_I2C_CH_ClearStatusFlag(I2C_CH_NUM,(uint32_t)XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
        /* Wait until TX FIFO is empty */
        while (!XMC_USIC_CH_TXFIFO_IsEmpty(I2C_CH_NUM))
        {
            /* wait until all data is sent by HW */
        }
        /* Transmit next command from I2C master to I2C slave */
        /* Send STOP conditon */
        XMC_I2C_CH_MasterStop(I2C_CH_NUM);
        for (volatile uint8_t gu8Index = 0; gu8Index < 5444; gu8Index++);
        XMC_I2C_CH_MasterStart(I2C_CH_NUM,SLAVE_ID, XMC_I2C_CH_CMD_READ);
        /* Wait for acknowledge and reset status */
        while((XMC_I2C_CH_GetStatusFlag(I2C_CH_NUM) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 0U)
        {
	       	/* wait for ACK from slave */
	}
        XMC_I2C_CH_ClearStatusFlag(I2C_CH_NUM,(uint32_t)XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);

	for(volatile uint8_t gu8Index=0;gu8Index <3;gu8Index++ ){
		ReceivedData1[gu8Index] =RecieveByte();
	}
	while (1U){
	}
}

Below are obtained output images 
Screenshot (210).png

 

0 Likes
1 Solution
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @smart ,

Apologies for the late response.

We don't have an EEPROM at our end to check it but interfacing an eeprom with controller is similar to interfacing an sensor with controller.

You need to write an driver,for that there are many resources available you can refer to them.

Please let me know if you need any help while porting the drivers to XMC.

Best Regards
Pradeep.

View solution in original post

0 Likes
8 Replies
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @smart ,

Could you please share the entire project that is DAVE or MTB project ?

Could please explain us your application because we see that you are trying to interface a pressure sensor ?

Best Regards
Pradeep.

0 Likes

Hi @Pradeep,

My application aim is to receive the data from the Pressure Sensor(BMP280) using the I2C protocol.

Best Regards 
Navneeth.

0 Likes
lock attach
Attachments are accessible only for community members.

Hi @Pradeep
Below I have attached the entire  DAVE project. 


 Best Regards 
Navneeth.

 

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @smart ,

We went through your project and below is our comments.

While interfacing an sensor with the controller there are some steps you need to follow :

1) Establish a Digital Interface with the controller  , In you case I2C Interface.

How to select the I2C interface in your case please please refer to the data sheet of the sensor.

2)After establishing communication then you need an driver of the specific sensor.

You cannot write or read the registers of sensor directly by using transmit API.

You need to write the driver based on the how  I2C write()  and I2C read() mentioned in the data sheet using the PDL of XMC .

So define the function READ() and WRITE() using PDL of XMC.

For more reference please refer to below Drivers.

Link : https://github.com/torvalds/linux/tree/master/drivers/iio/pressure

Link : https://github.com/boschsensortec/BMP280_driver/blob/master/bmp280.h

Hope this helps and let me know if you have any further queries.

Best Regards
Pradeep.

0 Likes
smart
Level 1
Level 1
10 sign-ins First like given 5 replies posted

Hi @Pradeep

Thank you for reply. I want initialize the I2C and just read the slave id.
As  I tested the same code with EEPROM by changing the slave addresses, register addresses but the output is same.
Could you please find the reason of cause?
As my requirement is to read the slave ID? Can you help me out in this ?



Thank you 
Smart

 

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @smart ,

Are you emulating a portion of flash as EEPROM for data storage ? If yes please refer to the app help of the EEPROM APP in DAVE for usage.

If you are using an external EEPROM then what EEPROM are you using and how to interface it with XMC refer to the data sheet of the particular EEPROM.

If you are facing any problems while interfacing please let me know.

Best Regards
Pradeep.

lock attach
Attachments are accessible only for community members.
smart
Level 1
Level 1
10 sign-ins First like given 5 replies posted

Hi @Pradeep

Thank you for the reply. I have attached the EEPROM below.

Can you please give a sample code to write and read a value in a particular location?

Best Regards
Smart

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @smart ,

Apologies for the late response.

We don't have an EEPROM at our end to check it but interfacing an eeprom with controller is similar to interfacing an sensor with controller.

You need to write an driver,for that there are many resources available you can refer to them.

Please let me know if you need any help while porting the drivers to XMC.

Best Regards
Pradeep.

0 Likes