cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

Nice to meet you. Thank you for seeing.

   

Please teach me how to transmit data to external 16 bit A/DC (AD5696, Analog Devices) by using I2C master in PSoC 5LP. I programmed C firmware refer to Sample Code "DelSig_I2CM" in PSoC creator, not only A/DC didn't work , but also SDA and SCL signal have been seen using oscilloscope. I think C firmware is highly likely to be wrong, but I couldn't understand reason.

   

------------------------------------------------------------------------

   

/* Parameters used:
*  I2C Master
*   Implementation      Fixed function
*   Data rate           400kbps
*   SDA SCL pin config  Open drain, drives low
*   Pull-up resistors   1.8kΩ each
*
*  Delta Sigma ADC
*    Resolution            12 bits
*    Conversion Rate       1000000 SPS
*    Input mode            Single ended
*/

   

#include <project.h>
#define I2C_SLAVE_ADDRESS    (12u)
#define WR_BUFFER_SIZE       (2u)

   

uint8   X_IN = 0u;
uint8   temp = 0u;
uint8   sample_segment[WR_BUFFER_SIZE];
uint16  result[3] = {0u};

   

int main(void)
{
    ADC_SAR_IN_Start();
    ADC_SAR_IN_StartConvert();
    I2CM_Start();
    CyGlobalIntEnable;
    
    for(;;)
    {   
        ADC_SAR_IN_IsEndConversion(ADC_SAR_IN_WAIT_FOR_RESULT);
        result[X_IN] = ADC_SAR_IN_GetResult16();
        sample_segment[0] = result[X_IN] >> 8u & 0x00FFu;
        sample_segment[1] = result[X_IN] & 0x00FFu;
        do
        {
            temp = I2CM_MasterWriteBuf(I2C_SLAVE_ADDRESS, (uint8 *)sample_segment, WR_BUFFER_SIZE, I2CM_MODE_COMPLETE_XFER);
        }
        while(temp != I2CM_MSTR_NO_ERROR);
        while(I2CM_MasterStatus() & I2CM_MSTAT_XFER_INP);
        temp = I2CM_MasterClearStatus();
    }
}

0 Likes
4 Replies
JoMe_264151
Expert II

Welcome in the forum.

   

It is easier for us to help when you post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

Your code looks ok at first sight, although I wouldn't try in a do-while loop to repeat an action when an error was returned.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Dear Bob

   

Thank you for reply.

   

I attached the bundled filed. 

   

>> although I wouldn't try in a do-while loop to repeat an action when an error was returned.

   

I can't understand mean...I'm sorry. 

0 Likes
Anonymous
Not applicable

Are you facing any issues in the project. I tested the attached project with Delsig_I2CM_Test01 as slave project and your project is working fine. I could see proper output at slave end.

   

1. Please make sure that I2C slave address and the I2C clock frequency are slave at both master and slave project. 

   

2. Once master and slave is programmed, please power the slave first and power the master as second. Let me know if this is working.

   

Thanks

   

Ramesh B

0 Likes
Anonymous
Not applicable

Thank you very much, I solved the problem.

   

I2C address was wrong.... I'm so sorry for easy mistake.

0 Likes