i2c returning i2c_timeout

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

dev
Posts: 6
Joined: Tue Feb 28, 2017 7:38 pm

i2c returning i2c_timeout

Post by dev »

Hi,
I am using chibios3 and STM32F411RE discovery board.
I am using cs43l22 ic. I have configured the pins for I2C in code as well. Here is look of my code. (Code is took from forum only)

Code: Select all

/*
 * codec_CS43L22.c
 *
 *  Created on: Jun 7, 2012
 *      Author: Kumar Abhishek
 */


// I2C address : 0x94
// PB9 : SDA
// PB6 : SCL
#include "ch.h"
#include "hal.h"
#include "codec.h"

//#include "chprintf.h"

const stm32_dma_stream_t* i2sdma;
static uint32_t i2stxdmamode=0;

uint16_t * playerThread;

static const I2CConfig i2cfg = {
    OPMODE_I2C,
    100000,
    FAST_DUTY_CYCLE_16_9,
};

#define I2S3_TX_DMA_CHANNEL                                                 \
  STM32_DMA_GETCHANNEL(STM32_SPI_SPI3_TX_DMA_STREAM,                        \
                       STM32_SPI3_TX_DMA_CHN)

static uint8_t txbuf[2]={0}, rxbuf[2]={0};

void codec_hw_init(void)
{
  palSetPadMode(GPIOB,6,4);
  palSetPadMode(GPIOB,9,4);

   // Fortunately, all pins have already been initialized in board.h

   // Start the i2c driver
   i2cStart(&CODEC_I2C, &i2cfg);

   // Reset the codec
   codec_hw_reset();

   // Write init sequence
   // Keep codec powered down initially
   codec_pwrCtl(0);

   codec_muteCtl(0);

   // Auto Detect Clock, MCLK/2
   codec_writeReg(0x05, 0x81);

   // Slave Mode, I2S Data Format
   codec_writeReg(0x06, 0x04);

   codec_pwrCtl(1);

   codec_volCtl(200);

   // Adjust PCM Volume
   codec_writeReg(0x1A, 0x0A);
   codec_writeReg(0x1B, 0x0A);

   // Disable the analog soft ramp
   codec_writeReg(0x0A, 0x00);

   // Disable the digital soft ramp
   codec_writeReg(0x0E, 0x04);

   // Disable the limiter attack level
   codec_writeReg(0x27, 0x00);

   codec_writeReg(0x1C, 0x80);
}

void codec_hw_reset(void)
{
   palClearPad(GPIOD, 4);
   chThdSleepMilliseconds(100);
   palSetPad(GPIOD, 4);
}

static void dma_i2s_interrupt(void* dat, uint32_t flags)
{
   dmaStreamDisable(i2sdma);

   chSysLockFromIsr();
   chEvtSignalFlagsI(playerThread, 1);
   chSysUnlockFromIsr();
}

static void codec_dma_init(void)
{
   i2sdma=STM32_DMA_STREAM(STM32_SPI_SPI3_TX_DMA_STREAM);

   i2stxdmamode = STM32_DMA_CR_CHSEL(I2S3_TX_DMA_CHANNEL) |
               STM32_DMA_CR_PL(STM32_SPI_SPI3_DMA_PRIORITY) |
               STM32_DMA_CR_DIR_M2P |
               STM32_DMA_CR_DMEIE |
               STM32_DMA_CR_TEIE |
               STM32_DMA_CR_TCIE |
               STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;

   int8_t b = dmaStreamAllocate(i2sdma,
         STM32_SPI_SPI3_IRQ_PRIORITY,
         (stm32_dmaisr_t)dma_i2s_interrupt,
         (void *)&SPID3);

//   if (!b)
//      chprintf((BaseChannel*)&SD2, "DMA Allocated Successfully to I2S3\r\n");

   dmaStreamSetPeripheral(i2sdma, &(SPI3->DR));
}

void codec_i2s_init(uint16_t sampleRate, uint8_t nBits)
{
   uint16_t prescale;
   uint32_t pllfreq=STM32_PLLI2SVCO / STM32_PLLI2SR_VALUE;

   if (nBits!=16)
      return;

   // SPI3 in I2S Mode, Master
   CODEC_I2S_ENABLE;

   CODEC_I2S->I2SCFGR=SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SCFG_1;

   // Master clock mode Fs * 256
   prescale=(pllfreq*10)/(256*sampleRate) + 5;
   prescale/=10;

//   chprintf((BaseChannel*)&SD2, "Prescale value:%d\r\n", prescale);

   if (prescale > 0xFF || prescale < 2) prescale=2;

   if (prescale & 0x01)
      CODEC_I2S->I2SPR=SPI_I2SPR_MCKOE | SPI_I2SPR_ODD | (prescale>>1);
   else
      CODEC_I2S->I2SPR=SPI_I2SPR_MCKOE | (prescale>>1);

   codec_dma_init();

   // Enable I2S DMA Request
   CODEC_I2S->CR2  = SPI_CR2_TXDMAEN;

   // Now Enable I2S
   CODEC_I2S->I2SCFGR|=SPI_I2SCFGR_I2SE;
}

void codec_writeReg(uint8_t addr, uint8_t data)
{
   txbuf[0]=addr;
   txbuf[1]=data;
   i2cMasterTransmitTimeout(&I2CD1, 0x94, txbuf, 2, NULL, 0, MS2ST(4));
}

void codec_pwrCtl(uint8_t pwr)
{
   if (pwr)
      codec_writeReg(0x02, 0x9E);
   else
      codec_writeReg(0x02, 0x01);
}

void codec_muteCtl(uint8_t mute)
{
   if (mute)
      codec_writeReg(0x04, 0xFF);
   else
      codec_writeReg(0x04, 0xAF);
}

void codec_volCtl(uint8_t vol)
{
   if (vol > 0xE6)
   {
      codec_writeReg(0x20, vol-0xE7);
      codec_writeReg(0x21, vol-0xE7);
   }
   else
   {
      codec_writeReg(0x20, vol+0x19);
      codec_writeReg(0x21, vol+0x19);
   }
}

void codec_selectAudioSource(uint8_t src)
{
   switch (src) {
      case CODEC_AUDIOSRC_DIGITAL:
         // Disable all pass through channels
         codec_writeReg(0x0E, 0x04);
         break;

      case CODEC_AUDIOSRC_MIC:
         // Select AIN4A/B for pass through
         codec_writeReg(0x08, 0x08);
         codec_writeReg(0x09, 0x08);
         codec_writeReg(0x0E, 0xC4);
         break;

      case CODEC_AUDIOSRC_FMRADIO:
         // Select AIN2A/B for pass through
         codec_writeReg(0x08, 0x02);
         codec_writeReg(0x09, 0x02);
         codec_writeReg(0x0E, 0xC4);
         break;
   }
}

// Send data to the codec via I2S
void codec_audio_send(void* txbuf, size_t n)
{
   dmaStreamSetMemory0(i2sdma, txbuf);
   dmaStreamSetTransactionSize(i2sdma, n);
   dmaStreamSetMode(i2sdma, i2stxdmamode | STM32_DMA_CR_MINC);
   dmaStreamClearInterrupt(i2sdma);
   dmaStreamEnable(i2sdma);
}

void codec_pauseResumePlayback(uint8_t pause)
{
   if (pause) {
      codec_muteCtl(1);
      codec_pwrCtl(0);

      CODEC_I2S->CR2=0;

   } else {
      codec_pwrCtl(1);

      CODEC_I2S->CR2=SPI_CR2_TXDMAEN;

      codec_muteCtl(0);
   }
}

void codec_sendBeep(void)
{
   codec_writeReg(0x1E, 0x00);
   codec_writeReg(0x1E, 0x80);
}


Whenever i am checking state of i2c, it is coming as I2C_LOCK.

i think it is not at all getting started. (i don't have dso or logic analyser to check).
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: i2c returning i2c_timeout

Post by Giovanni »

Hi,

There are lots of things that can go wrong, I cannot tell just looking at the code. Several suggestions:

1) Update to the latest ChibiOS 16.1.7.
2) Look at the I2C demos under /testhal/STM32, those are guaranteed to work, use them as base.
3) Look at this troubleshooting guide for I2C on STM32: http://wiki.chibios.org/dokuwiki/doku.p ... e_shooting

Giovanni
dev
Posts: 6
Joined: Tue Feb 28, 2017 7:38 pm

Re: i2c returning i2c_timeout

Post by dev »

Hi,
I did follow this link. http://wiki.chibios.org/dokuwiki/doku.p ... e_shooting
And I re-checked the the suggested steps.

My codebase is latest synced.
My pin config is also seems to be fine.
mcu_conf is also updated.
here is attached files.
CS43L22.7z
project
(16.39 KiB) Downloaded 422 times
dev
Posts: 6
Joined: Tue Feb 28, 2017 7:38 pm

Re: i2c returning i2c_timeout

Post by dev »

I found one correction, board.h file was bit incorrect. I have corrected but no luck. Still audio/tone is not hearing.

Code: Select all

#define VAL_GPIOB_MODER             (PIN_MODE_INPUT(GPIOB_PIN0) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN1) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN2) |           \
                                     PIN_MODE_ALTERNATE(GPIOB_SWO) |        \
                                     PIN_MODE_INPUT(GPIOB_PIN4) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN5) |           \
                                     PIN_MODE_ALTERNATE(AF_I2C_SCL) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN7) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN8) |           \
                                     PIN_MODE_ALTERNATE(AF_I2C_SDA) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN10) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN11) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN12) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN13) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN14) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN15))
#define VAL_GPIOB_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOB_PIN0) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN1) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN2) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_SWO) |        \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN4) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN5) |       \
                                     PIN_OTYPE_PUSHPULL(AF_I2C_SCL) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN7) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN8) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN9) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN10) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN11) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN12) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN13) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN14) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN15))
#define VAL_GPIOB_OSPEEDR           (PIN_OSPEED_100M(GPIOB_PIN0) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN1) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN2) |          \
                                     PIN_OSPEED_100M(GPIOB_SWO) |           \
                                     PIN_OSPEED_100M(GPIOB_PIN4) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN5) |          \
                                     PIN_OSPEED_50M(AF_I2C_SCL) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN7) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN8) |          \
                                     PIN_OSPEED_50M(AF_I2C_SDA) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN10) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN11) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN12) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN13) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN14) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN15))
#define VAL_GPIOB_PUPDR             (PIN_PUPDR_PULLUP(GPIOB_PIN0) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN1) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN2) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_SWO) |          \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN4) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN5) |         \
                                     PIN_PUPDR_FLOATING(AF_I2C_SCL) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN7) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN8) |         \
                                     PIN_PUPDR_FLOATING(AF_I2C_SDA) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN10) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN11) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN12) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN13) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN14) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN15))
#define VAL_GPIOB_ODR               (PIN_ODR_HIGH(GPIOB_PIN0) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN1) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN2) |             \
                                     PIN_ODR_HIGH(GPIOB_SWO) |              \
                                     PIN_ODR_HIGH(GPIOB_PIN4) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN5) |             \
                                     PIN_ODR_HIGH(AF_I2C_SCL) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN7) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN8) |             \
                                     PIN_ODR_HIGH(AF_I2C_SDA) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN10) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN11) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN12) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN13) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN14) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN15))
#define VAL_GPIOB_AFRL              (PIN_AFIO_AF(GPIOB_PIN0, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN1, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN2, 0) |           \
                                     PIN_AFIO_AF(GPIOB_SWO, 0) |            \
                                     PIN_AFIO_AF(GPIOB_PIN4, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN5, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN6, 4) |           \
                                     PIN_AFIO_AF(GPIOB_PIN7, 0))
#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_PIN8, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN9, 4) |           \
                                     PIN_AFIO_AF(GPIOB_PIN10, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN11, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN12, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN13, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN14, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN15, 0))


Any idea, how to debug this?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: i2c returning i2c_timeout

Post by Giovanni »

Is the I2C address correct? in ChibiOS it is just the 7 bits value without the RW bit.

Anyway knowing what it is going on would require a logic analyzer.

Giovanni
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: i2c returning i2c_timeout

Post by RoccoMarco »

dev wrote:I found one correction, board.h file was bit incorrect. I have corrected but no luck. Still audio/tone is not hearing.

Code: Select all

#define VAL_GPIOB_MODER             (PIN_MODE_INPUT(GPIOB_PIN0) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN1) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN2) |           \
                                     PIN_MODE_ALTERNATE(GPIOB_SWO) |        \
                                     PIN_MODE_INPUT(GPIOB_PIN4) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN5) |           \
                                     PIN_MODE_ALTERNATE(AF_I2C_SCL) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN7) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN8) |           \
                                     PIN_MODE_ALTERNATE(AF_I2C_SDA) |           \
                                     PIN_MODE_INPUT(GPIOB_PIN10) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN11) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN12) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN13) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN14) |          \
                                     PIN_MODE_INPUT(GPIOB_PIN15))
#define VAL_GPIOB_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOB_PIN0) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN1) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN2) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_SWO) |        \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN4) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN5) |       \
                                     PIN_OTYPE_PUSHPULL(AF_I2C_SCL) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN7) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN8) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN9) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN10) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN11) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN12) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN13) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN14) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN15))
#define VAL_GPIOB_OSPEEDR           (PIN_OSPEED_100M(GPIOB_PIN0) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN1) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN2) |          \
                                     PIN_OSPEED_100M(GPIOB_SWO) |           \
                                     PIN_OSPEED_100M(GPIOB_PIN4) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN5) |          \
                                     PIN_OSPEED_50M(AF_I2C_SCL) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN7) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN8) |          \
                                     PIN_OSPEED_50M(AF_I2C_SDA) |          \
                                     PIN_OSPEED_100M(GPIOB_PIN10) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN11) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN12) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN13) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN14) |         \
                                     PIN_OSPEED_100M(GPIOB_PIN15))
#define VAL_GPIOB_PUPDR             (PIN_PUPDR_PULLUP(GPIOB_PIN0) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN1) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN2) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_SWO) |          \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN4) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN5) |         \
                                     PIN_PUPDR_FLOATING(AF_I2C_SCL) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN7) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN8) |         \
                                     PIN_PUPDR_FLOATING(AF_I2C_SDA) |         \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN10) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN11) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN12) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN13) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN14) |        \
                                     PIN_PUPDR_PULLUP(GPIOB_PIN15))
#define VAL_GPIOB_ODR               (PIN_ODR_HIGH(GPIOB_PIN0) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN1) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN2) |             \
                                     PIN_ODR_HIGH(GPIOB_SWO) |              \
                                     PIN_ODR_HIGH(GPIOB_PIN4) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN5) |             \
                                     PIN_ODR_HIGH(AF_I2C_SCL) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN7) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN8) |             \
                                     PIN_ODR_HIGH(AF_I2C_SDA) |             \
                                     PIN_ODR_HIGH(GPIOB_PIN10) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN11) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN12) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN13) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN14) |            \
                                     PIN_ODR_HIGH(GPIOB_PIN15))
#define VAL_GPIOB_AFRL              (PIN_AFIO_AF(GPIOB_PIN0, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN1, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN2, 0) |           \
                                     PIN_AFIO_AF(GPIOB_SWO, 0) |            \
                                     PIN_AFIO_AF(GPIOB_PIN4, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN5, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN6, 4) |           \
                                     PIN_AFIO_AF(GPIOB_PIN7, 0))
#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_PIN8, 0) |           \
                                     PIN_AFIO_AF(GPIOB_PIN9, 4) |           \
                                     PIN_AFIO_AF(GPIOB_PIN10, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN11, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN12, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN13, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN14, 0) |          \
                                     PIN_AFIO_AF(GPIOB_PIN15, 0))


Any idea, how to debug this?


Hi dev,
can you explain better what was the error in the board file?
There aren't board file for Discovery F411 in chibios3, what board file do you have used as starting point?
Hawhill
Posts: 7
Joined: Tue Oct 18, 2016 1:28 pm
Been thanked: 1 time

Re: i2c returning i2c_timeout

Post by Hawhill »

dev wrote:I found one correction, board.h file was bit incorrect. I have corrected but no luck. Still audio/tone is not hearing.

Why not start with something simpler to test, like reading some config setting or status bit?

I'm not sure the CS43L22 is supposed to utter a thing (not even the beeps) without proper clock setup on the I2S related channels.
dev
Posts: 6
Joined: Tue Feb 28, 2017 7:38 pm

Re: i2c returning i2c_timeout

Post by dev »

@Giovanni,
There were two i2c driver files as i2cV1 and i2cV2.
So, in i2cV1, i tried address (0x94>>1), Because we are again left shifting there.
And in i2cV2, i tried 0x94 only.
(AD0/A0 is connected to ground).
Which address i should try? :|

@RoccoMarco, i took RT-STM32F411RE-NUCLEO for reference, and changed board files accordingly.

@Hawhill, that is good idea to start with. :)

I will post my status, soon.
Here is my code,
https://github.com/devdprj/audioplayer/
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: i2c returning i2c_timeout

Post by Giovanni »

You need to divide the address byte by two on all drivers, regardless the type. On the F411 you need to use I2Cv1.

You are using the provided makefiles, aren't you?

Giovanni
dev
Posts: 6
Joined: Tue Feb 28, 2017 7:38 pm

Re: i2c returning i2c_timeout

Post by dev »

Hi,
yes, i am using address as

Code: Select all

#define CS43L22_ADDR    (0x94 >> 1)


And I2C driver version I2CV1 only,

I was doing code debugging, Following are my observation,
1. Whenever i was reading using following function,

Code: Select all

   i2cMasterTransmitTimeout(&I2CD1, CS43L22_ADDR, txbuf, 1, rxbuf, 2, MS2ST(4));
   

i was getting Value as 0.
2. i2c_lld_serve_error_interrupt this interrupt handler was getting hit continously.
3. I2C->DR register contains always address as data.
4. case was being hit continously.

Code: Select all

  case I2C_EV5_MASTER_MODE_SELECT:

5. i checked getError function which was returning 0.
Post Reply