GithubHelp home page GithubHelp logo

sandbox's People

Contributors

cedricq avatar cedricquentin avatar

Stargazers

 avatar

Watchers

 avatar

sandbox's Issues

Qout in 1m tick



uint32_t tick_i2c = 0 ;

uint16_t ReadQout()
{  
    if (i2c_state == I2C_INIT)
    {
        if (tick_i2c <= 300)
        {
            HAL_GPIO_WritePin(CmdQout_GPIO_Port, CmdQout_Pin, GPIO_PIN_SET);
        }    
        else if (tick_i2c <= 400)
        {
            HAL_GPIO_WritePin(CmdQout_GPIO_Port, CmdQout_Pin, GPIO_PIN_RESET);
        }
        else
        {
            uint8_t status = HAL_I2C_Master_Transmit(&hi2c1, SFM3219_ADDRESS<<1, cmd, 3, 1000);
            if (status == HAL_OK)
            {
                i2c_state = I2C_READ;
                i2c_retry = 0;
            }
            else
            {
                HAL_UART_Transmit(&huart3, "INIT_ERROR\n\0", strlen("INIT_ERROR\n\0"), 100);
            }
            tick_i2c = 0;
        } 
        tick_i2c++;
    }
    else if (i2c_state == I2C_READ)
    {
        uint8_t i2c_rcv_buff[3] = {0x00, 0x00, 0x00};
        uint8_t status = HAL_I2C_Master_Receive(&hi2c1, SFM3219_ADDRESS<<1, i2c_rcv_buff, 3, 1000);
        if (status == HAL_OK)
        {
            if (SF04_CheckCrc (i2c_rcv_buff, 2, i2c_rcv_buff[2]) != CHECKSUM_ERROR)
            {
                rawQout = (int16_t)(((uint16_t)i2c_rcv_buff[0])<<8 | i2c_rcv_buff[0]);
            }
            else
            {
                HAL_UART_Transmit(&huart3, "CHECKSUM_ERROR\n\0", strlen("CHECKSUM_ERROR\n\0"), 100);
                i2c_retry++;
            }
        }
        else
        {
            HAL_UART_Transmit(&huart3, "READING_ERROR\n\0", strlen("READING_ERROR\n\0"), 100);
            i2c_retry++;
        }
        if (i2c_retry >= 10)
        {
            tick_i2c = 0;
            i2c_state = I2C_INIT;
        }
    }
    return rawQout ;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.