This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

I want to have SPI communication between AFE4300 EVM board and atemega128

Other Parts Discussed in Thread: AFE4300

I want to use BCM mode and just one channel.

when atemega128 gives AFE4300-EVM board "read ADC"protocol, the AFE4300 replys result value.

when setting calibration value(R56~59), the result value is not linear. And Ready Pin does not operate.

I think that the value is dummy.

But changing R56~59 give me different value......also, alternating between continuous mode and single shot mode operate successfully. 

How can i check some other??

  • Hi,

    Could you please let us know what signals are interfaced between AFE4300 EVM and ATmega128?

    Regards,
    Prabin
  • void ADC_READ() // read a byte
    {
    unsigned char address,high, low;

    PORTB = 0x00; // CS = 1
    SPDR = 0x20; //read ADCresister
    while((SPSR & 0x80) == 0x00); // transmit complete ?

    SPDR=0x00;
    while((SPSR & 0x80) == 0x00);
    high=SPDR;

    SPDR=0x00;
    while((SPSR & 0x80) == 0x00);
    low = SPDR;
    PORTB = 0x01; // CS = 0
    /*
    PORTB = 0x00; // CS = 1
    SPDR = 0x00; //read ADCresister
    while((SPSR&0x80)!=0x80); // transmit complete ?

    SPDR=high;
    while((SPSR&0x80)!=0x80);

    SPDR=low;
    while((SPSR&0x80)!=0x80);
    PORTB = 0x01;
    */

    UARTsend(high);
    UARTsend(low);

    }

    void AFE4300_WRITE(unsigned char address,unsigned char high,unsigned char low)
    {

    PORTB = 0x00; // CS = 0
    SPDR = address;
    while((SPSR&0x80)!=0x80); // transmit complete ?

    SPDR = high;
    while((SPSR&0x80)!=0x80); // transmit complete ?

    SPDR = low;
    while((SPSR&0x80)!=0x80); // transmit complete ?
    PORTB = 0x01; // CS = 1


    }

    void set_up()
    {

    AFE4300_WRITE(ADDRESS_ADC_CONTROL_REGISTER1,0xC1,0x43);
    AFE4300_WRITE(ADDRESS_MISC_REGISTER1,0x80,0x00);
    AFE4300_WRITE(ADDRESS_MISC_REGISTER2,0x7F,0xFF);
    AFE4300_WRITE(ADDRESS_DEVICE_CONTROL1,0x60,0x06);
    AFE4300_WRITE(ADDRESS_IQ_MODE_ENABLE,0x00,0x00);
    AFE4300_WRITE(ADDRESS_WEIGHT_SCALE_CONTROL,0x00,0x00);
    AFE4300_WRITE(ADDRESS_BCM_DAC_FREQ,0x00,0x40); //DAC freq=64KHz
    AFE4300_WRITE(ADDRESS_DEVICE_CONTROL2,0x00,0x00);
    AFE4300_WRITE(ADDRESS_ADC_CONTROL_REGISTER2,0x00,0x63);
    AFE4300_WRITE(ADDRESS_MISC_REGISTER3,0x00,0x30);
    }

    void calibration(char c_mode)
    {


    switch (c_mode)
    {
    case 0: // calibarion off
    AFE4300_WRITE(0x0A, 0x00,0x00);
    AFE4300_WRITE(0x0B,0x00,0x00);
    break;

    case 1: // calibration (R58 99ohm)
    AFE4300_WRITE(0x0A,0x01,0x01);
    AFE4300_WRITE(0x0B,0x01,0x01);
    // AFE4300_WRITE(ADDRESS_ADC_CONTROL_REGISTER1,0xC1,0xC3);
    break;

    case 2: //calibration (R57 949ohm)
    AFE4300_WRITE(0x0A,0x02,0x02);
    AFE4300_WRITE(0x0B,0x02,0x02);
    // AFE4300_WRITE(ADDRESS_ADC_CONTROL_REGISTER1,0xC1,0xC3);
    break;

    case 3: //calibration (R56 699ohm)
    AFE4300_WRITE(0x0A,0x02,0x01);
    AFE4300_WRITE(0x0B,0x02,0x01);
    // AFE4300_WRITE(ADDRESS_ADC_CONTROL_REGISTER1,0xC1,0xC3);
    break;

    case 4: //calibration (R59 196ohm)
    AFE4300_WRITE(0x0A,0x01,0x02);
    AFE4300_WRITE(0x0B,0x01,0x02);
    // AFE4300_WRITE(ADDRESS_ADC_CONTROL_REGISTER1,0xC1,0xC3);
    break;

    }


    }
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    int main()
    {

    DDRF=0x01;

    char i=1;
    char command;

    init();

    USART_init();

    UART_Ready = 1;

    timer1_init();

    SPI_init();

    set_up();

    // measurement();
    calibration(2);

    while(1)
    {

    if(Datachk())
    {
    command = UARTreceive();
    Act(command);

    }

    if(action==1)
    {


    ADC_READ();

    action=0;

    }


    }

    return 0;
    }

    --------------------------------------------------------------------
    and when I make use of OUT and VSENSE PORT, the result value is true......... why happen??

    thank you.
  • Hi,

    There are some problem with the register setting in " set_up()" function. Top three lines for "set_up()" should be replaced by following lines:

    AFE4300_WRITE(ADDRESS_ADC_CONTROL_REGISTER1,0xC1,0x40);
    AFE4300_WRITE(ADDRESS_MISC_REGISTER1,0x00,0x00);
    AFE4300_WRITE(ADDRESS_MISC_REGISTER2,0xFF,0xFF);

    Once you write these correct settings and give 1MHz CLK to AFE4300, you should see 128Hz signal on "Data Ready" pin.
    Also , When using calibration circuit to measure R57 ( 10 KOhms) , you will get value for R57 || ( R59 + R56 + R58) i.e. 10KOhm || 1.050 KOhm.

    One solution would be remove R59 and measure only R58, R57 and R56 using your "calibration()" function. In this case you will get individual values for each of three calibration registers.

    Regards,
    Prabin

  • it's so very informative. thank you