Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
KhoaNguyen
Level 2
Level 2
50 sign-ins 10 likes given 5 replies posted

Hello community!
I have a project that reads ML8511 + BME280 + PSoC 6 BLE sensors
Previously when I only had the ML8511 sensor, I could connect BLE and send data via Android APP!
But after adding the BME280 sensor to the project, the BLE connection error occurred!
I think the problem is with my code!
I have attached my project! Hope everyone can take a look and help me revise this project!
Thank!.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
ADSW
Moderator
Moderator
Moderator
250 sign-ins 50 solutions authored 25 likes received

Hello @KhoaNguyen , 

From your code, at least you need to call Cy_BLE_ProcessEvents() once in 20ms ( advertising interval ). 
Instead of using do-while, you can use conditional-if to check the status of sensor BME and decrease the delay from 1000ms to 5. 

From line 170 in main_cm4.c

 

 

//BME280
if( getTick() - bme_tick >= 500)
        {
            error = BME280_ReadStatusRegister(&status_reg);
            if (error == BME280_OK && ( (status_reg & 16) == 0))
            {
                error = BME280_ReadData(&bme280, BME280_ALL_COMP);
                if (error == BME280_OK)
                {
                    P = ((float) bme280.data.pressure) / 100 ;
                    T = ((float) bme280.data.temperature)/ 100;
                    H = ((float) bme280.data.humidity) / 1024.0 ;
                    sprintf(buf_txt,(const char*)("Pressure:    %shPa   \t\r\n"), ftoa(P,strF,2));
                    UART_PutString(buf_txt) ;
                    sprintf(buf_txt,(const char*)("Temperature: %s*C    \t\r\n"), ftoa(T,strF,2));
                    UART_PutString(buf_txt) ;
                    sprintf(buf_txt,(const char*)("Humidity:    %s      \t\r\n"), ftoa(H,strF,2));
                    UART_PutString(buf_txt) ;
                }
                else
                {
                    UART_PutString("Error: ");
                    switch(error)
                    {
                        case(BME280_E_DEV_NOT_FOUND):
                            UART_PutString("BME280_E_DEV_NOT_FOUND\r\n");
                        break;
                        case(BME280_E_NULL_PTR):
                            UART_PutString("BME280_E_NULL_PTR\r\n");
                        break;
                        case(BME280_E_INVALID_LEN):
                            UART_PutString("BME280_E_INVALID_LEN\r\n");
                        break;
                        case(BME280_E_COMM_FAIL):
                            UART_PutString("BME280_E_COMM_FAIL\r\n");
                        break;
                        case(BME280_E_SLEEP_MODE_FAIL):
                            UART_PutString("BME280_E_SLEEP_MODE_FAIL\r\n");
                        break;
                        case(BME280_E_NVM_COPY_FAILED):
                            UART_PutString("BME280_E_NVM_COPY_FAILED\r\n");
                        break;
                    }
                    BME280_Reset(&bme280);    
                }
            }
            else
            {
                UART_PutString("BME280 is missing !\r\n");
            }
            bme_tick = getTick();
        }
        CyDelay(10);

 

 

 
warm regards,
ADSW

View solution in original post

2 Replies
MuhammadNanda_K
Moderator
Moderator
Moderator
250 sign-ins 250 replies posted 50 likes received

Hello @KhoaNguyen ,

I just assigned to your thread.
To be more clarify:

  1. Is your sensor data is already correct if you print that in serial terminal ?
  2. Is your BLE advertising (listed in the mobile apps) ?

It is because after trying your code, it is not listed in apps.

I am still checking on my side.
Meanwhile, please kindly give more information as per my questions.

Thank you and regards,
Muhammad Nanda

lock attach
Attachments are accessible only for community members.
ADSW
Moderator
Moderator
Moderator
250 sign-ins 50 solutions authored 25 likes received

Hello @KhoaNguyen , 

From your code, at least you need to call Cy_BLE_ProcessEvents() once in 20ms ( advertising interval ). 
Instead of using do-while, you can use conditional-if to check the status of sensor BME and decrease the delay from 1000ms to 5. 

From line 170 in main_cm4.c

 

 

//BME280
if( getTick() - bme_tick >= 500)
        {
            error = BME280_ReadStatusRegister(&status_reg);
            if (error == BME280_OK && ( (status_reg & 16) == 0))
            {
                error = BME280_ReadData(&bme280, BME280_ALL_COMP);
                if (error == BME280_OK)
                {
                    P = ((float) bme280.data.pressure) / 100 ;
                    T = ((float) bme280.data.temperature)/ 100;
                    H = ((float) bme280.data.humidity) / 1024.0 ;
                    sprintf(buf_txt,(const char*)("Pressure:    %shPa   \t\r\n"), ftoa(P,strF,2));
                    UART_PutString(buf_txt) ;
                    sprintf(buf_txt,(const char*)("Temperature: %s*C    \t\r\n"), ftoa(T,strF,2));
                    UART_PutString(buf_txt) ;
                    sprintf(buf_txt,(const char*)("Humidity:    %s      \t\r\n"), ftoa(H,strF,2));
                    UART_PutString(buf_txt) ;
                }
                else
                {
                    UART_PutString("Error: ");
                    switch(error)
                    {
                        case(BME280_E_DEV_NOT_FOUND):
                            UART_PutString("BME280_E_DEV_NOT_FOUND\r\n");
                        break;
                        case(BME280_E_NULL_PTR):
                            UART_PutString("BME280_E_NULL_PTR\r\n");
                        break;
                        case(BME280_E_INVALID_LEN):
                            UART_PutString("BME280_E_INVALID_LEN\r\n");
                        break;
                        case(BME280_E_COMM_FAIL):
                            UART_PutString("BME280_E_COMM_FAIL\r\n");
                        break;
                        case(BME280_E_SLEEP_MODE_FAIL):
                            UART_PutString("BME280_E_SLEEP_MODE_FAIL\r\n");
                        break;
                        case(BME280_E_NVM_COPY_FAILED):
                            UART_PutString("BME280_E_NVM_COPY_FAILED\r\n");
                        break;
                    }
                    BME280_Reset(&bme280);    
                }
            }
            else
            {
                UART_PutString("BME280 is missing !\r\n");
            }
            bme_tick = getTick();
        }
        CyDelay(10);

 

 

 
warm regards,
ADSW