Hello,
i changed the software parts DRubeša and now i cant see the signals with the osciloscope.
Attachment 2840
there is the full signal of EEPROM_SendByte() function.
this new program can exit from this function, i think something is bad. Can someone help?
This is my code:
#include "xmc_scu.h"
#include "xmc_gpio.h"
#include "xmc_i2c.h"
#define EEPROM_I2C_ADR 0xA1
#define SDA_PIN P0_7
#define SCL_PIN P0_8
void Init_I2C (void);
void EEPROM_SendByte (uint8_t MemoryAddress, uint8_t DataToSend);
uint8_t EEPROM_ReadByte (uint8_t MemoryAddress);
uint8_t ReceivedData;
XMC_SCU_CLOCK_CONFIG_t clock_config;
XMC_GPIO_CONFIG_t led1_config;
XMC_GPIO_CONFIG_t sda_pin_config;
XMC_GPIO_CONFIG_t scl_pin_config;
/* I2C configuration */
XMC_USIC_CH_t *i2c = XMC_I2C0_CH1;
XMC_I2C_CH_CONFIG_t i2c_cfg;
void Init_I2C (void){
/* Configure Clock */
clock_config.pclk_src = XMC_SCU_CLOCK_PCLKSRC_MCLK; /*PCLK = MCLK*/
clock_config.fdiv = 0; /**< Fractional divider */
clock_config.idiv = 0; /**MCLK = 32MHz */
XMC_SCU_CLOCK_Init(&clock_config);
/* Configure LED1 */
led1_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
XMC_GPIO_Init(XMC_GPIO_PORT0,6, &led1_config);
/* I2C configuration */
i2c_cfg.baudrate = 320000U;
XMC_I2C_CH_Init(i2c, &i2c_cfg);
XMC_I2C_CH_Start(i2c);
/* I2C initialization sequence*/
XMC_I2C_CH_SetInputSource(i2c, XMC_I2C_CH_INPUT_SDA , USIC0_C1_DX0_P0_7);
XMC_I2C_CH_SetInputSource(i2c, XMC_I2C_CH_INPUT_SCL , USIC0_C1_DX1_P0_8);
/* I2C port pin configuration*/
sda_pin_config.mode = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT7;
sda_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
XMC_GPIO_Init(SDA_PIN, &sda_pin_config);
scl_pin_config.mode = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT7;
scl_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
XMC_GPIO_Init(SCL_PIN, &scl_pin_config);
}
void EEPROM_SendByte (uint8_t MemoryAddress, uint8_t DataToSend){
XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR, XMC_I2C_CH_CMD_WRITE); // I2C send repeated start command (with slave address) to write Data to PCA9502
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterTransmit(i2c, MemoryAddress); // I2C send
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
XMC_I2C_CH_MasterTransmit(i2c, DataToSend); // I2C send TxData=IO_STATE
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
XMC_I2C_CH_MasterStop(i2c);
}
uint8_t EEPROM_ReadByte (uint8_t MemoryAddress){
uint8_t data = 0;
XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR, XMC_I2C_CH_CMD_WRITE); // I2C send repeated start command (with slave address) to write Data to PCA9502
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterTransmit(i2c, MemoryAddress); // I2C send
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterStop(i2c);
XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR, XMC_I2C_CH_CMD_READ); // I2C send repeated start command (with slave address) to Read Data from PCA9502
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterReceiveNack(i2c); // I2C send dummy with NACK to read only one byte
while((XMC_I2C_CH_GetStatusFlag(i2c) & (XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICAT ION)) == 1U){} // wait until AIR or RI
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICAT ION); // clear both AIR and RI
data = XMC_I2C_CH_GetReceivedData(i2c); // get RxData from RBUF
XMC_I2C_CH_MasterStop(i2c);
return data;
}
int main(void)
{
Init_I2C();
while(1U)
{
ReceivedData = 0;
EEPROM_SendByte(0x55, 0x20);
ReceivedData = EEPROM_ReadByte(0x55);
if (ReceivedData==0x20){
XMC_GPIO_ToggleOutput(XMC_GPIO_PORT0,6);
}
}
}
Best regards,
Paul
i changed the software parts DRubeša and now i cant see the signals with the osciloscope.
Attachment 2840
there is the full signal of EEPROM_SendByte() function.
this new program can exit from this function, i think something is bad. Can someone help?
This is my code:
#include "xmc_scu.h"
#include "xmc_gpio.h"
#include "xmc_i2c.h"
#define EEPROM_I2C_ADR 0xA1
#define SDA_PIN P0_7
#define SCL_PIN P0_8
void Init_I2C (void);
void EEPROM_SendByte (uint8_t MemoryAddress, uint8_t DataToSend);
uint8_t EEPROM_ReadByte (uint8_t MemoryAddress);
uint8_t ReceivedData;
XMC_SCU_CLOCK_CONFIG_t clock_config;
XMC_GPIO_CONFIG_t led1_config;
XMC_GPIO_CONFIG_t sda_pin_config;
XMC_GPIO_CONFIG_t scl_pin_config;
/* I2C configuration */
XMC_USIC_CH_t *i2c = XMC_I2C0_CH1;
XMC_I2C_CH_CONFIG_t i2c_cfg;
void Init_I2C (void){
/* Configure Clock */
clock_config.pclk_src = XMC_SCU_CLOCK_PCLKSRC_MCLK; /*PCLK = MCLK*/
clock_config.fdiv = 0; /**< Fractional divider */
clock_config.idiv = 0; /**MCLK = 32MHz */
XMC_SCU_CLOCK_Init(&clock_config);
/* Configure LED1 */
led1_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
XMC_GPIO_Init(XMC_GPIO_PORT0,6, &led1_config);
/* I2C configuration */
i2c_cfg.baudrate = 320000U;
XMC_I2C_CH_Init(i2c, &i2c_cfg);
XMC_I2C_CH_Start(i2c);
/* I2C initialization sequence*/
XMC_I2C_CH_SetInputSource(i2c, XMC_I2C_CH_INPUT_SDA , USIC0_C1_DX0_P0_7);
XMC_I2C_CH_SetInputSource(i2c, XMC_I2C_CH_INPUT_SCL , USIC0_C1_DX1_P0_8);
/* I2C port pin configuration*/
sda_pin_config.mode = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT7;
sda_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
XMC_GPIO_Init(SDA_PIN, &sda_pin_config);
scl_pin_config.mode = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT7;
scl_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
XMC_GPIO_Init(SCL_PIN, &scl_pin_config);
}
void EEPROM_SendByte (uint8_t MemoryAddress, uint8_t DataToSend){
XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR, XMC_I2C_CH_CMD_WRITE); // I2C send repeated start command (with slave address) to write Data to PCA9502
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterTransmit(i2c, MemoryAddress); // I2C send
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
XMC_I2C_CH_MasterTransmit(i2c, DataToSend); // I2C send TxData=IO_STATE
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED);
XMC_I2C_CH_MasterStop(i2c);
}
uint8_t EEPROM_ReadByte (uint8_t MemoryAddress){
uint8_t data = 0;
XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR, XMC_I2C_CH_CMD_WRITE); // I2C send repeated start command (with slave address) to write Data to PCA9502
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterTransmit(i2c, MemoryAddress); // I2C send
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterStop(i2c);
XMC_I2C_CH_MasterStart(i2c, EEPROM_I2C_ADR, XMC_I2C_CH_CMD_READ); // I2C send repeated start command (with slave address) to Read Data from PCA9502
while((XMC_I2C_CH_GetStatusFlag(i2c) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 1U){} // wait until ACK
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED); // clear ACK flag in register PSR
XMC_I2C_CH_MasterReceiveNack(i2c); // I2C send dummy with NACK to read only one byte
while((XMC_I2C_CH_GetStatusFlag(i2c) & (XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICAT ION)) == 1U){} // wait until AIR or RI
XMC_I2C_CH_ClearStatusFlag(i2c, XMC_I2C_CH_STATUS_FLAG_RECEIVE_INDICATION |
XMC_I2C_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICAT ION); // clear both AIR and RI
data = XMC_I2C_CH_GetReceivedData(i2c); // get RxData from RBUF
XMC_I2C_CH_MasterStop(i2c);
return data;
}
int main(void)
{
Init_I2C();
while(1U)
{
ReceivedData = 0;
EEPROM_SendByte(0x55, 0x20);
ReceivedData = EEPROM_ReadByte(0x55);
if (ReceivedData==0x20){
XMC_GPIO_ToggleOutput(XMC_GPIO_PORT0,6);
}
}
}
Best regards,
Paul