Closed spusuluri closed 1 year ago
still not functional after addition of code. Can't scan the board.
You code, as of a minute ago, compiles and runs just fine on my DK. It does not connect (though it is advertising), so that it an issue... but it otherwise runs.
How would I fix the issue of not connecting? Because on my end, when I compile and run the code, the DK's leds are not on and there's no logging. Would fixing the connection allow for the logging and leds to turn on?
Blocking log message in the ADC. Remove that and everything connects.
It seems that the bluetooth only works for me when I use the debug mode (after update it still needs to be used in debug mode for some odd reason). I get this error when I click on button 2 to send a notification.
[00:00:44.740,570] <wrn> bt_att: Unable to allocate ATT TX meta
[00:00:44.740,600] <wrn> bt_gatt: No buffer available to send notification
[00:00:44.740,600] <err> Final_Project: Could not send BT notification (err: -12)
Update: New code has battery level working. But, there is still an error with sending the RMS values. It will be sent in hex values but it doesn't do it correctly and can occasionally get the error above. I believe the error in the code is somewhere in the code snippet below.
void collect_rms_data(struct k_timer *rms_collection_timer){
/*
The output to the bluetooth will be a hex number and will have
*/
LOG_DBG("RMS Data Collected");
RMS_values[rms_data_count]= (uint8_t) adc_sin100_RMS;
rms_data_count++;
RMS_values[rms_data_count]= (uint8_t) adc_sin500_RMS;
if(rms_data_count == 9){
rms_data_count = 0;
k_timer_stop(rms_collection_timer);
}
else{
rms_data_count++;
}
}
void stop_rms_data(struct k_timer *rms_collection_timer){
LOG_DBG("RMS Data Stopped");
}
void boardled3_toggle(struct k_timer *vbus_timer){
gpio_pin_toggle_dt(&board_led3);
LOG_DBG("LED 3 Toggle");
}
void boardled3_stop(struct k_timer *vbus_timer){
LOG_DBG("LED 3 turned off.");
gpio_pin_set_dt(&board_led3, 0);
}
/*Callbacks*/
void board_button1_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
LOG_DBG("Button 1 pressed.");
k_timer_start(&rms_collection_timer, K_MSEC(RMS_DATA_SAMPLE_RATE_MSEC), K_MSEC(RMS_DATA_SAMPLE_RATE_MSEC));
}
void board_button2_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
int err;
err = send_data_notification(current_conn, RMS_values, 1);
if (err){
LOG_ERR("Could not send BT notification (err: %d)", err);
}
else{
LOG_INF("BT data transmitted.");
}
}
It might not be directly related to the code that your called out. It looks like your timer functions have for loops in them; that is not advised. Timer functions need to run quickly, like ISRs, and for loops are not good. Instead, the timer should toggle a boolean and have the main loop execute on that for loop.... or you need to consider changing the timer logic to do something faster repeatedly to achieve the same function as the for loop but w/o taking so much time and blocking other processes.
When I added the CONFIG_BT to the prj.cof file, the board does not work. The LEDs do not light up and the logging functions do not occur. When I remove it and build it ,the board works just fine. Is this supposed to happen?