Example #1
0
void writeEEPROM1(unsigned char address, char data){
    if( i2c1_slave_ready(MEP_EEPROM_ID, 0x0FFF) == 0 )
        return;

    char _address[] = {MEP_EEPROM_ID, (char)address};
    i2c1_master_fputs(&data, 1, _address, 2);
}
Example #2
0
void con_cmd_handler(void)
{
    if(con_entry_flag && con_entry_index > 0 && !con_arg_tolong)
    {
        con_cmd_from_entry(con_entry);
        con_printf("\r\n");

        if(con_arg_tolong)
        {
            con_printf("Arg too long. Max lenght = ");
            con_putcl(CON_ARG_WIDTH + 48);
            con_printf("\r\n>>");
            con_arg_tolong = FALSE;
            con_entry_flag = FALSE;
            return;
        }

        if((strcmp(con_cmd, "test") == 0) ||
                (strcmp(con_cmd, "test_m1") == 0))
        {
            char test[10] = {4,1,9,1,9,5,6,7,8,9};
            char recv[10] = {0,0,0,0,0,0,0,0,0,0};
            char len = 10;
            char address[] = {I2C_EEPROM_ID, 5};
            int count = 0;
            int i = 0;

            //Test write
            count = i2c1_master_fputs(test, len, address, 2);

            //Print results
            sprintf(buff, "Test write: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", test[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Wrote %d from %d bytes\n", count, len);
            con_printf(buff);

            //Test read
            count = i2c1_master_fgets(recv, len, address, 2);

            //Print results
            sprintf(buff, "Test read: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", recv[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Read %d from %d bytes\n", count, len);
            con_printf(buff);

            con_printf("\n>>");
            con_arg_tolong = FALSE;
            con_entry_flag = FALSE;
            return;
        }

        if(strcmp(con_cmd, "test_m2") == 0)
        {
            char test[10] = {3,1,2,1,2,5,6,7,8,2};
            char recv[10] = {0,0,0,0,0,0,0,0,0,0};
            char len = 10;
            char address[] = {I2C_EEPROM_ID, 3};
            int count = 0;
            int i = 0;

            //Test write
            count = i2c2_master_fputs(test, len, address, 2);

            //Print results
            sprintf(buff, "Test write: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", test[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Wrote %d from %d bytes\n", count, len);
            con_printf(buff);

            //Test read
            count = i2c2_master_fgets(recv, len, address, 2);

            //Print results
            sprintf(buff, "Test read: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", recv[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Read %d from %d bytes\n", count, len);
            con_printf(buff);

            con_printf("\n>>");
            con_arg_tolong = FALSE;
            con_entry_flag = FALSE;
            return;
        }

        if(strcmp(con_cmd, "test_m3") == 0)
        {
            char test[10] = {3,1,8,1,2,8,6,7,8,1};
            char recv[10] = {0,0,0,0,0,0,0,0,0,0};
            char len = 10;
            char address[] = {I2C_EEPROM_ID, 3};
            int count = 0;
            int i = 0;

            //Test write
            count = i2c3_master_fputs(test, len, address, 2);

            //Print results
            sprintf(buff, "Test write: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", test[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Wrote %d from %d bytes\n", count, len);
            con_printf(buff);

            //Test read
            count = i2c3_master_fgets(recv, len, address, 2);

            //Print results
            sprintf(buff, "Test read: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", recv[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Read %d from %d bytes\n", count, len);
            con_printf(buff);

            con_printf("\n>>");
            con_arg_tolong = FALSE;
            con_entry_flag = FALSE;
            return;
        }

        if(strcmp(con_cmd, "test_m1s2") == 0)
        {
            char test[10] = {0,1,2,3,4,5,6,7,8,9};
            char recv[10] = {0,0,0,0,0,0,0,0,0,0};
            char len = 10;
            char address[] = {0x0B, 3};
            int count = 0;
            int i = 0;

            //Test write
            count = i2c1_master_fputs(test, len, address, 2);

            //Print results
            sprintf(buff, "Test write: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", test[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Wrote %d from %d bytes\n", count, len);
            con_printf(buff);

            //Test read
            count = i2c1_master_fgets(recv, len, address, 2);

            //Print results
            sprintf(buff, "Test read: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", recv[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Read %d from %d bytes\n", count, len);
            con_printf(buff);

            con_printf("\n>>");
            con_arg_tolong = FALSE;
            con_entry_flag = FALSE;
            return;
        }

        if(strcmp(con_cmd, "test_m2s1") == 0)
        {
            char test[10] = {0,1,2,3,4,5,6,7,8,9};
            char recv[10] = {0,0,0,0,0,0,0,0,0,0};
            char len = 10;
            char address[] = {0x0A, 3};
            int count = 0;
            int i = 0;

            //Test write
            count = i2c2_master_fputs(test, len, address, 2);

            //Print results
            sprintf(buff, "Test write: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", test[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Wrote %d from %d bytes\n", count, len);
            con_printf(buff);

            //Test read
            count = i2c2_master_fgets(recv, len, address, 2);

            //Print results
            sprintf(buff, "Test read: ");
            con_printf(buff);
            for(i=0; i<len; i++)
            {
                sprintf(buff, "%d, ", recv[i]);
                con_printf(buff);
            }
            sprintf(buff, "\n    Read %d from %d bytes\n", count, len);
            con_printf(buff);

            con_printf("\n>>");
            con_arg_tolong = FALSE;
            con_entry_flag = FALSE;
            return;
        }

        //to get here the cmd has to fail al the comparisons
        con_error_unknown_cmd();
        con_printf("\n>>");
    }

    con_arg_tolong = FALSE;
    con_entry_flag = FALSE;
    return;
}