|
请问 怎么把下面这个代码的8 bit ADC值改成 16 bit 再发送到 手机的 Master Control panel (MCP) 上? 我如果只更改 uint8_t adc_result 改为 uint_16 adc_result. 就会出现很多错误信息。- /* Interrupt handler for ADC data ready event */
- void ADC_IRQHandler(void)
- {
- uint8_t adc_result;
-
- /* Clear dataready event */
- NRF_ADC->EVENTS_END = 0;
- /* Write ADC result both to the UART and over BLE */
- adc_result = NRF_ADC->RESULT;
- app_uart_put(adc_result);
- ble_nus_send_string(&m_nus, &adc_result, 1);
- nrf_gpio_pin_toggle(LED_3); //indicate on LED that the ADC interrupt handler is executing
-
- //Use the STOP task to save current. Workaround for PAN_028 rev1.5 anomaly 1.
- NRF_ADC->TASKS_STOP = 1;
-
- //Release the external crystal
- sd_clock_hfclk_release();
- }
复制代码
这是 "ble_nus_send_string()" 的指令:- uint32_t ble_nus_send_string(ble_nus_t * p_nus, uint8_t * string, uint16_t length)
- {
- ble_gatts_hvx_params_t hvx_params;
- if (p_nus == NULL)
- {
- return NRF_ERROR_NULL;
- }
-
- if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
- {
- return NRF_ERROR_INVALID_STATE;
- }
-
- if (length > BLE_NUS_MAX_DATA_LEN)
- {
- return NRF_ERROR_INVALID_PARAM;
- }
-
- memset(&hvx_params, 0, sizeof(hvx_params));
- hvx_params.handle = p_nus->rx_handles.value_handle;
- hvx_params.p_data = string;
- hvx_params.p_len = &length;
- hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
-
- return sd_ble_gatts_hvx(p_nus->conn_handle, &hvx_params);
- }
复制代码 这里是 github 上的代码。
https://github.com/faweiz/nrf51-ADC-examples/blob/master/adc_example_with_softdevice_and_UART/adc_example_with_softdevice_and_UART/main.c
请大家指教。谢谢!
|
|