Hello,
I have the following application code (based on the template project from the SDK):
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_uart.h"
#include "nrf_delay.h"
#include "nrf_drv_twi.h"
#include "nordic_common.h"
#include "boards.h"
#include "app_uart.h"
#include "boards.h"
void UART_Init(void);
void TWI_Init(nrf_drv_twi_t Instance);
void UART_EventHandler(app_uart_evt_t* p_event);
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
static const nrf_drv_twi_t TWI_Instance = NRF_DRV_TWI_INSTANCE(0);
int main(void)
{
uint8_t sample_data;
uint32_t UART_Error;
bsp_board_init(BSP_INIT_LEDS);
UART_Init();
TWI_Init(TWI_Instance);
printf("Go");
for(uint8_t Address = 1; Address < 128; Address++)
{
if(nrf_drv_twi_rx(&TWI_Instance, Address, &sample_data, sizeof(sample_data)) == NRF_SUCCESS)
{
printf("TWI device detected at address 0x%x.", Address);
}
}
while(true)
{
}
}
void UART_EventHandler(app_uart_evt_t* p_event)
{
if(p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_communication);
}
else if(p_event->evt_type == APP_UART_FIFO_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_code);
}
else if(p_event->evt_type == APP_UART_DATA_READY)
{
uint8_t Char;
app_uart_get(&Char);
app_uart_put(Char);
}
}
void UART_Init(void)
{
uint32_t Error;
app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_DISABLED,
false,
NRF_UART_BAUDRATE_115200
};
APP_UART_FIFO_INIT(&comm_params,
256,
256,
UART_EventHandler,
APP_IRQ_PRIORITY_LOWEST,
Error);
APP_ERROR_CHECK(Error);
}
void TWI_Init(nrf_drv_twi_t Instance)
{
uint32_t Error;
nrf_drv_twi_config_t twi_config = {
.scl = ARDUINO_SCL_PIN,
.sda = ARDUINO_SDA_PIN,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};
Error = nrf_drv_twi_init(&Instance, &twi_config, NULL, NULL);
APP_ERROR_CHECK(Error);
nrf_drv_twi_enable(&Instance);
}
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
while(1)
{
bsp_board_led_on(0);
nrf_delay_ms(500);
}
}
The receive callback is working and I get all the characters from my terminal, but I don´t get any output with printf.
How can I fix this?