Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stdint.h>
- #include <stdio.h>
- #include "app_uart.h"
- #include "app_error.h"
- #include "nrf_delay.h"
- #include "nrf.h"
- #include "bsp.h"
- #include "nrf_drv_twi.h"
- #include "nrf_drv_uart.h"
- // TWI --------------------------------------------------
- #define DEVICE_SCL_PIN 29
- #define DEVICE_SDA_PIN 6
- nrf_drv_twi_t twi_instance = NRF_DRV_TWI_INSTANCE(0);
- void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context){
- }
- void twi_init (void)
- {
- ret_code_t err_code;
- const nrf_drv_twi_config_t twi_config = {
- .scl = DEVICE_SCL_PIN,
- .sda = DEVICE_SDA_PIN,
- .frequency = NRF_TWI_FREQ_100K,
- .interrupt_priority = APP_IRQ_PRIORITY_HIGH
- };
- err_code = nrf_drv_twi_init(&twi_instance, &twi_config, twi_handler, NULL);
- APP_ERROR_CHECK(err_code);
- nrf_drv_twi_enable(&twi_instance);
- }
- //UART ----------------------------------------------------------
- #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
- #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
- #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
- void uart_error_handle(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);
- }
- }
- #define RX_PIN_NUMBER 25
- #define TX_PIN_NUMBER 24
- #define CTS_PIN_NUMBER 23
- #define RTS_PIN_NUMBER 22
- #define HWFC false
- /**
- * @brief Function for main application entry.
- */
- int main(void)
- {
- uint32_t err_code;
- twi_init();
- const app_uart_comm_params_t comm_params =
- {
- RX_PIN_NUMBER,
- TX_PIN_NUMBER,
- RTS_PIN_NUMBER,
- CTS_PIN_NUMBER,
- APP_UART_FLOW_CONTROL_ENABLED,
- false,
- UART_BAUDRATE_BAUDRATE_Baud250000
- };
- APP_UART_FIFO_INIT(&comm_params,
- UART_RX_BUF_SIZE,
- UART_TX_BUF_SIZE,
- uart_error_handle,
- APP_IRQ_PRIORITY_LOWEST,
- err_code);
- APP_ERROR_CHECK(err_code);
- uint8_t test;
- while (true)
- {
- nrf_delay_ms(10);
- unsigned char message2[] = " outcome";
- message2[0] = 0xAA;
- nrf_drv_twi_tx(&twi_instance, 8, message2, sizeof(message2), false);
- nrf_delay_ms(10);
- //uint8_t data_buffer[2] = {4,2};
- //nrf_drv_uart_selvtx(data_buffer,2);
- uint8_t ch = 0;
- app_uart_get(&ch);
- //uint8_t mess[] = {0x55, 1,2,3,4}
- uint8_t tasd = 5;
- test = app_uart_put(tasd);
- app_uart_flush();
- uint8_t details[4] = {test, NRF_SUCCESS, NRF_SUCCESS==test, ch};
- nrf_drv_twi_tx(&twi_instance, 8, details, sizeof(details), false);
- nrf_delay_ms(10);
- app_uart_put(120);
- nrf_delay_ms(1000);
- // uint8_t cr;
- // while (app_uart_get(&cr) != NRF_SUCCESS);
- // while (app_uart_put(cr) != NRF_SUCCESS);
- //
- // if (cr == 'q' || cr == 'Q')
- // {
- // printf(" \r\nExit!\r\n");
- //
- // while (true)
- // {
- // // Do nothing.
- // }
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement