cancel
Showing results for 
Search instead for 
Did you mean: 

STR752 I2C Slave problem

ucoskun
Associate II
Posted on January 14, 2008 at 14:00

STR752 I2C Slave problem

2 REPLIES 2
ucoskun
Associate II
Posted on December 27, 2007 at 09:49

Hello,

I'm encountering problems with I2C Slave operation. Can anyone tell me what the problem is? What am I missing? Any help is appreciated. IHere is my code:

I'm also attaching the whole code.

// I2C Configuration

void I2C_Configuration(void)

{

I2C_InitTypeDef I2C_InitStructure;

/* I2C configuration */

I2C_InitStructure.I2C_GeneralCall = I2C_GeneralCall_Disable;

I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

I2C_InitStructure.I2C_CLKSpeed = 100000;

I2C_InitStructure.I2C_OwnAddress = 0x02;

/* I2C Peripheral Enable */

I2C_Cmd (ENABLE);

I2C_ITConfig(ENABLE); // yeni

/* Apply I2C configuration after enabling it */

I2C_Init(&I2C_InitStructure);

}

// EIC Configuration

void EIC_Configuration(void)

{

EIC_IRQInitTypeDef EIC_IRQInitStructure;

/* Configure and enable I2C_IRQChannel */

EIC_IRQInitStructure.EIC_IRQChannel = I2C_IRQChannel;

EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;

EIC_IRQInitStructure.EIC_IRQChannelCmd= ENABLE;

EIC_IRQInit(&EIC_IRQInitStructure);

/* Configure and enable RTC_IRQChannel */

EIC_IRQInitStructure.EIC_IRQChannel = RTC_IRQChannel;

EIC_IRQInitStructure.EIC_IRQChannelPriority = 2;

EIC_IRQInitStructure.EIC_IRQChannelCmd= ENABLE;

EIC_IRQInit(&EIC_IRQInitStructure);

/* ADC IRQ Channel configuration */

EIC_IRQInitStructure.EIC_IRQChannel = ADC_IRQChannel;

EIC_IRQInitStructure.EIC_IRQChannelPriority = 3;

EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;

EIC_IRQInit(&EIC_IRQInitStructure);

/* Enable the interrupt controller */

EIC_IRQCmd(ENABLE);

}

// GPIO Configuration

void GPIO_Configuration(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

/* SCL and SDA I2C pins configuration */

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ;

GPIO_Init(GPIO0, &GPIO_InitStructure);

//...

}

// MRCC Configuration

void MRCC_Configuration(void)

{

/* MRCC system reset(for debug purpose) */

MRCC_DeInit();

/* Wait for OSC4M start-up */

OSC4MStartUpStatus = MRCC_WaitForOSC4MStartUp();

if(OSC4MStartUpStatus == SUCCESS)

{

/* Set HCLK to 30MHz */

MRCC_HCLKConfig(MRCC_CKSYS_Div2);

/* Set CKTIM to 30MHz */

MRCC_CKTIMConfig(MRCC_HCLK_Div1);

/* Set PCLK to 30MHz */

MRCC_PCLKConfig(MRCC_CKTIM_Div1);

/* Set CK_SYS to 60 MHz */

MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);

}

/* GPIO pins optimized for 3V3 operation */

MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);

/* Enable GPIO and UART0 clock */

MRCC_PeripheralClockConfig(MRCC_Peripheral_I2C | MRCC_Peripheral_ADC | MRCC_Peripheral_GPIO | MRCC_Peripheral_UART0, ENABLE);

// Here is the interrupt ruotine:

void I2C_IRQHandler(void)

{

switch (I2C_GetLastEvent())

{

case I2C_EVENT_SLAVE_ADDRESS_MATCHED: // EV1

Rx_Idx = Tx_Idx = 0;

break;

case I2C_EVENT_SLAVE_BYTE_RECEIVED: // EV2

I2C0_Buffer_Rx[Rx_Idx++] = I2C_ReceiveData();

break;

case I2C_EVENT_SLAVE_BYTE_TRANSMITTED: // EV3

I2C_SendData(I2C0_Buffer_Tx[Tx_Idx++]);

break;

case I2C_EVENT_SLAVE_ACK_FAILURE: // EV3-1

I2C_SendData(0xFF);

break;

case I2C_EVENT_SLAVE_STOP_DETECTED: // EV4

Rx_Idx = Tx_Idx = 0;

break;

default:

break;

}

}

[ This message was edited by: ucoskun on 02-01-2008 19:56 ]

christophe239955_st
Associate II
Posted on January 14, 2008 at 14:00

It seems to me the problem has nothing to do with the software,interrupt configuration is correct. Perhaps a hardware issue.

Chris.