Skip to content
Snippets Groups Projects
main.c 3.35 KiB
Newer Older
  • Learn to ignore specific revisions
  • Pascal Koch's avatar
    Pascal Koch committed
    #include <pico/stdlib.h>
    
    Pascal Koch's avatar
    Pascal Koch committed
    #include <hardware/i2c.h>
    
    Pascal Koch's avatar
    Pascal Koch committed
    #include <stdio.h>
    #include <unistd.h>
    
    Pascal Koch's avatar
    Pascal Koch committed
    
    
    unsigned *SDApinctrl = (void *)(IO_BANK0_BASE + IO_BANK0_GPIO0_CTRL_OFFSET);
    unsigned *SCLpinctrl = (void *)(IO_BANK0_BASE + IO_BANK0_GPIO1_CTRL_OFFSET);
    
    const uint8_t init[4] = {0x21, 0xa0, 0xe1, 0x81};
    const uint8_t zeile[8] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x10, 0x12, 0x14};
    const uint8_t fill[17] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
    const uint8_t empty[17] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    const uint8_t achtel[17] = {0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    const uint8_t viertel[17] = {0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    const uint8_t dreiachtel[17] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    const uint8_t hälfte[17] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    const uint8_t fünfachtel[17] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    const uint8_t dreiviertel[17] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
    const uint8_t siebenachtel[17] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00};
    const uint8_t ganzes[17] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00};
    
    int main()
    {
    
    Pascal Koch's avatar
    Pascal Koch committed
    
    
    Pascal Koch's avatar
    Pascal Koch committed
        i2c_init(i2c_default, 100000);
    
        gpio_set_function(0, GPIO_FUNC_I2C);
        gpio_set_function(1, GPIO_FUNC_I2C);
    
    Pascal Koch's avatar
    Pascal Koch committed
    
        gpio_pull_up(1);
        gpio_pull_up(0);
    
    Pascal Koch's avatar
    Pascal Koch committed
    
    
        i2c_write_blocking(i2c_default, 0x70, &init[0], 1, false);
        i2c_write_blocking(i2c_default, 0x70, &init[1], 1, false);
        i2c_write_blocking(i2c_default, 0x70, &init[2], 1, false);
        i2c_write_blocking(i2c_default, 0x70, &init[3], 1, false);
    
        i2c_write_blocking(i2c_default, 0x70, zeile, 4, false);
    
        i2c_write_blocking(i2c_default, 0x70, empty, 17, false);
    
        i2c_write_blocking(i2c_default, 0x70, achtel, 17, false);
    
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
        }
    
    
        i2c_write_blocking(i2c_default, 0x70, viertel, 17, false);
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
        }
    
    
        i2c_write_blocking(i2c_default, 0x70, dreiachtel, 17, false);
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
        }
    
    
        i2c_write_blocking(i2c_default, 0x70, hälfte, 17, false);
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
    
        i2c_write_blocking(i2c_default, 0x70, fünfachtel, 17, false);
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
        }
    
    
        i2c_write_blocking(i2c_default, 0x70, dreiviertel, 17, false);
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
        }
    
    
        i2c_write_blocking(i2c_default, 0x70, siebenachtel, 17, false);
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
        }
    
    
        i2c_write_blocking(i2c_default, 0x70, ganzes, 17, false);
        for (int j = 0; j < 10000000; j++)
        {
    
    Pascal Koch's avatar
    Pascal Koch committed
            volatile int i = 0;
    
    Pascal Koch's avatar
    Pascal Koch committed
        }
    
    
    Pascal Koch's avatar
    Pascal Koch committed
        return 0;
    }