Hi, i am working on TWI sensor example in SDK11 i have connected MMa7660 to PCA10040 board as per the GIPIOs. and am integrated BLE app uart to the same TWI sensor example code and connected to nRFTool box Application. and i am able to observe x,y,z values in termite continuously. Problem is when i am sending the x,y,z (converted to string) values by ble_nus_string_send() the device became stuck and also UART is stopping. if i restart again its gets connected and when it comes to the ble_nus_string_send() again it crashes.
is there any conflict b/w ble_nus_string_send and TWI operation.
here is my code:
/**
-
@brief UART initialization. */ void twi_init (void) { ret_code_t err_code;
const nrf_drv_twi_config_t twi_mma_7660_config = { .scl = ARDUINO_SCL_PIN, .sda = ARDUINO_SDA_PIN, .frequency = NRF_TWI_FREQ_100K, .interrupt_priority = APP_IRQ_PRIORITY_HIGH };
err_code = nrf_drv_twi_init(&m_twi_mma_7660, &twi_mma_7660_config, twi_handler, NULL); APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi_mma_7660); }
void read_data(sample_t * p_new_sample) {
static uint8_t sample_idx;
static uint8_t prev_tilt;
sample_t * p_sample = &m_sample_buffer[sample_idx];
/* Subtracting oldest sample. */
m_sum.x -= p_sample->x.conv;
m_sum.y -= p_sample->y.conv;
m_sum.z -= p_sample->z.conv;
p_sample->tilt = p_new_sample->tilt;
int_to_uint(&p_sample->x.conv, p_new_sample->x.raw);
int_to_uint(&p_sample->y.conv, p_new_sample->y.raw);
int_to_uint(&p_sample->z.conv, p_new_sample->z.raw);
/* Adding new sample. This way we always have defined number of samples. */
m_sum.x += p_sample->x.conv;
m_sum.y += p_sample->y.conv;
m_sum.z += p_sample->z.conv;
++sample_idx;
if (sample_idx >= NUMBER_OF_SAMPLES)
{
sample_idx = 0;
}
if (sample_idx == 0 || (prev_tilt && (prev_tilt != p_sample->tilt)))
{
char const * orientation;
switch ((p_sample->tilt >> 2) & 0x07)
{
case LEFT:
orientation = "LEFT";
// printf("L\n");
break;
case RIGHT:
orientation = "RIGHT";
// printf("R\n");
break;
case DOWN:
orientation = "DOWN";
// printf("D\n");
break;
case UP:
orientation = "UP";
break;
default:
orientation = "?";
break;
}
printf("X: %3d Y: %3d Z: %3d | %s \r\n",
m_sum.x / NUMBER_OF_SAMPLES,
m_sum.y / NUMBER_OF_SAMPLES,
m_sum.z / NUMBER_OF_SAMPLES,orientation);
ble_nus_string_send(&m_nus,orientation,strlen(orientation));
}