Hello,
I trying to use the i2c to read with my i.mx6 board from the DSP.
my i.mx6 board is the master -> eZdsp should be slave !
i only can read one byte from the DSP ! when i try to read more than one byte its not working !
i use the read() function on the i.mx6 board.
this works with one bye! ->
int numberBytes = EZDSP_BUFFER; int bytesRead = read(file, this->dataBuffer, 1); std::cout << "bytes Read = "<< bytesRead << std::endl; std::cout << "bytes Read = "<< this->dataBuffer[0] << std::endl; if (bytesRead == -1){ std::cout << "Failure to read" << std::endl; }
But when it try to read morge then one byte like this:
int numberBytes = EZDSP_BUFFER; int bytesRead = read(file, this->dataBuffer, 512); std::cout << "bytes Read = "<< bytesRead << std::endl; std::cout << "bytes Read = "<< this->dataBuffer[0] << std::endl; if (bytesRead == -1){ std::cout << "Failure to read" << std::endl; }
its not working !
please help me... here is my eZdps code :
#include "csl_i2c.h" #include "cslr_i2c.h" #include "csl_dma.h" #include <csl_general.h> #include "do_fft.h" #include "setup_irq.h" #include "stdio.h" #include "setup_i2c.h" #include "ref_data.h" #define CSL_I2C_ICOAR_OADDR_SETSLAVEADD (0x0060u) #define CSL_I2C_SYS_CLK (10) #define CSL_I2C_BUS_FREQ (400) #define CSL_I2C_DATA_SIZE (512) #define CSL_I2C_OWN_ADDR (0x002F) CSL_I2cSetup i2cSetup; CSL_I2cConfig i2cConfig; CSL_DMA_Handle dmaWrHandle; CSL_DMA_Handle dmaRdHandle; CSL_DMA_Config dmaConfig; CSL_DMA_ChannelObj dmaWrChanObj; CSL_DMA_ChannelObj dmaRdChanObj; Uint16 i2cTxCount; Uint16 i2cRxCount; Uint16 i2cErrInTx; Uint16 stopDetected = FALSE; Uint8 gI2cRdBuf[CSL_I2C_DATA_SIZE]; Uint8 gI2cWrBuf[CSL_I2C_DATA_SIZE]; Uint16 i2cRxCount; Uint8 I2C_active_flag; volatile Uint16 dataLength; volatile Uint16 looper; extern DATA magnitude[OFFSET]; void setup_i2c(void) { for(looper = 0; looper < CSL_I2C_DATA_SIZE; looper++) { gI2cWrBuf[looper] = looper; gI2cRdBuf[looper] = 0x0000; } Uint16 statusByte; CSL_Status status; status = I2C_init(CSL_I2C0); if(status != CSL_SOK) { printf("I2C Init Failed!!\n"); } // i2cConfig.icoar = CSL_I2C_ICOAR_DEFVAL; // i2cConfig.icimr = CSL_I2C_ICIMR_DEFVAL; // i2cConfig.icclkl = CSL_I2C_ICCLK_DEFVAL; // i2cConfig.icclkh = CSL_I2C_ICCLK_DEFVAL; i2cConfig.iccnt = CSL_I2C_DATA_SIZE; // i2cConfig.icsar = CSL_I2C_ICSAR_DEFVAL; // i2cConfig.icmdr = CSL_I2C_ICMDR_WRITE_DEFVAL; // i2cConfig.icemdr = CSL_I2C_ICEMDR_DEFVAL; // i2cConfig.icpsc = CSL_I2C_ICPSC_DEFVAL; status = I2C_config(&i2cConfig); if(status != CSL_SOK) { printf("I2C Config Failed!!\n"); } statusByte = activate_i2c_events(); if(statusByte != CSL_SOK) { printf("Event Init Failed!!\n"); } statusByte = init_i2c_interface(); if(statusByte != CSL_SOK) { printf("I2C Init Failed!!\n"); } } CSL_Status activate_i2c_events() { CSL_Status result = 0; CSL_I2cIsrAddr i2cIsrAddr; CSL_Status status; /* Enable I2C NACK Error Event */ status = I2C_eventEnable(CSL_I2C_EVENT_NACK); /* Enable I2C NACK Error Event */ if(status != CSL_SOK) { printf("I2C Event enable Failed!!\n"); } status = I2C_eventEnable(CSL_I2C_EVENT_ICXRDY); /* Enable I2C Tx Ready Event */ if(status != CSL_SOK) { printf("I2C Event enable Failed!!\n"); } status = I2C_eventEnable(CSL_I2C_EVENT_ICRRDY); /** I2C Receive ReaDY event*/ if(status != CSL_SOK) { printf("I2C Event enable Failed!!\n"); return(result); } status = I2C_eventEnable(CSL_I2C_EVENT_AAS); /** Address As Slave event */ if(status != CSL_SOK) { printf("I2C Event enable Failed!!\n"); return(result); } status = I2C_eventEnable(CSL_I2C_EVENT_SCD); /** Stop Condition Detected event*/ if(status != CSL_SOK) { printf("I2C Event enable Failed!!\n"); return(result); } status = I2C_eventEnable(CSL_I2C_EVENT_ARDY); /** register Access ReaDY event*/ if(status != CSL_SOK) { printf("I2C Event enable Failed!!\n"); return(result); } status = I2C_eventEnable(CSL_I2C_EVENT_AL); /** Arbitration Loss event */ if(status != CSL_SOK) { printf("I2C Event enable Failed!!\n"); return(result); } /* Set the I2C call back function address */ i2cIsrAddr.alAddr = CSL_i2cAlCallback; i2cIsrAddr.nackAddr = CSL_i2cNackCallback; i2cIsrAddr.ardyAddr = CSL_i2cArdyCallback; i2cIsrAddr.rrdyAddr = CSL_i2cRxCallback; i2cIsrAddr.xrdyAddr = CSL_i2cTxCallback; i2cIsrAddr.scdAddr = CSL_i2cScdCallback; i2cIsrAddr.aasAddr = CSL_i2cAasCallback; status = I2C_setCallback(&i2cIsrAddr); if(status != CSL_SOK) { printf("I2C Set callback Failed!!\n"); return(result); } return 0; } CSL_Status init_i2c_interface() { CSL_Status result = 0; CSL_I2cSetup i2cSetup; CSL_Status status; /* Setup I2C module */ i2cSetup.addrMode = CSL_I2C_ADDR_7BIT; i2cSetup.bitCount = CSL_I2C_BC_8BITS; i2cSetup.loopBack = CSL_I2C_LOOPBACK_DISABLE; i2cSetup.freeMode = CSL_I2C_FREEMODE_DISABLE; i2cSetup.repeatMode = CSL_I2C_REPEATMODE_ENABLE; i2cSetup.ownAddr = CSL_I2C_ICOAR_OADDR_SETSLAVEADD; i2cSetup.sysInputClk = CSL_I2C_SYS_CLK; i2cSetup.i2cBusFreq = CSL_I2C_BUS_FREQ; status = I2C_setup(&i2cSetup); if(status != CSL_SOK) { printf("I2C Setup Failed!!\n"); return(result); } CSL_FINST(i2cHandle->i2cRegs->ICEMDR, I2C_ICMDR_MST, CLEAR); CSL_FINST(i2cHandle->i2cRegs->ICMDR, I2C_ICMDR_STB, CLEAR); CSL_FINST(i2cHandle->i2cRegs->ICMDR, I2C_ICMDR_RM, SET); // RM,STP, STT -> Repeat mode transfer: START condition, slave address, continuous data transfers until STOP condition or next START condition CSL_FINST(CSL_I2C_0_REGS->ICMDR, I2C_ICMDR_STP, CLEAR); CSL_FINST(CSL_I2C_0_REGS->ICMDR, I2C_ICMDR_STT, SET); //CSL_I2C0_WRITEREG(ICMDR,CSL_I2C_ICMDR_MST_CLEAR); //CSL_I2C0_WRITEREG(ICMDR, //CSL_I2C0_WRITEREG(ICEMDR,CSL_I2C_ICEMDR_BCM_SET); //CSL_I2C0_WRITEREG(ICMDR,CSL_I2C_ICMDR_STT_SET); //CSL_FINST(i2cHandle->i2cRegs->ICEMDR, I2C_ICEMDR_BCM, SET); i2cErrInTx = FALSE; i2cTxCount = 0; dataLength = CSL_I2C_DATA_SIZE; return 0; } interrupt void i2c_isr(void) { Uint16 eventId; eventId = I2C_getEventId(); if(eventId != 0) { i2cHandle->I2C_isrDispatchTable[eventId - 1](); } } void CSL_i2cAlCallback(void) { printf("i2cAlCallback\n"); } /** * \brief I2C No acknowledgement callback * * \param None * * \return None */ void CSL_i2cNackCallback(void) { i2cErrInTx = TRUE; printf("i2cNackcallback\n"); } /** * \brief I2C Access ready callback * * \param None * * \return None */ void CSL_i2cArdyCallback(void) { printf("i2cArdyCallback\n"); } /** * \brief I2C Receive ready callback * * \param None * * \return None */ void CSL_i2cRxCallback(void) { gI2cRdBuf[i2cRxCount++] = CSL_I2C_0_REGS->ICDRR; dataLength--; printf("i2cRxCallback\n"); } /** * \brief I2C Transmit ready callback * * \param None * * \return None */ void CSL_i2cTxCallback(void) { CSL_I2C_0_REGS->ICDXR = gI2cWrBuf[i2cTxCount++];//(Uint8)magnitude[i2cTxCount++]; //gI2cWrBuf[i2cTxCount++]; dataLength--; printf("i2cTXCallback\n"); } /** * \brief I2C Stop condition detected callback * * \param None * * \return None */ void CSL_i2cScdCallback(void) { stopDetected = TRUE; printf("i2cScdCallback\n"); } /** * \brief I2C Address as slave callback * * \param None * * \return None */ void CSL_i2cAasCallback(void) { printf("i2cAasCallback\n"); }