Included uart, test commit
This commit is contained in:
parent
ae595ce678
commit
7b8585012a
48
main.c
48
main.c
|
|
@ -1,5 +1,6 @@
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/drivers/uart.h>
|
||||||
|
|
||||||
#include <nrf_gpio.h>
|
#include <nrf_gpio.h>
|
||||||
#include <nrf_timer.h>
|
#include <nrf_timer.h>
|
||||||
|
|
@ -7,6 +8,41 @@
|
||||||
#define TST_CLK_PIN 17 //this is led 0 pin on nrf52-dk
|
#define TST_CLK_PIN 17 //this is led 0 pin on nrf52-dk
|
||||||
#define FREQ_MEASURE_PIN 11
|
#define FREQ_MEASURE_PIN 11
|
||||||
|
|
||||||
|
const struct device *uart0 = DEVICE_DT_GET(DT_NODELABEL(uart0));
|
||||||
|
|
||||||
|
|
||||||
|
struct uart_config uart_cfg = {
|
||||||
|
.baudrate = 9600,
|
||||||
|
.parity = UART_CFG_PARITY_NONE,
|
||||||
|
.stop_bits = UART_CFG_STOP_BITS_1,
|
||||||
|
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
|
||||||
|
.data_bits = UART_CFG_DATA_BITS_8,
|
||||||
|
};
|
||||||
|
|
||||||
|
void send_str(const struct device *uart, char *str)
|
||||||
|
{
|
||||||
|
int msg_len = strlen(str);
|
||||||
|
|
||||||
|
for (int i = 0; i < msg_len; i++) {
|
||||||
|
uart_poll_out(uart, str[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
printk("Device %s sent: \"%s\"\n", uart->name, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void recv_str(const struct device *uart, char *str)
|
||||||
|
{
|
||||||
|
char *head = str;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
while (!uart_poll_in(uart, &c)) {
|
||||||
|
*head++ = c;
|
||||||
|
}
|
||||||
|
*head = '\0';
|
||||||
|
|
||||||
|
printk("Device %s received: \"%s\"\n", uart->name, str);
|
||||||
|
}
|
||||||
|
|
||||||
void gpio_clock_8m(uint32_t pin_number)
|
void gpio_clock_8m(uint32_t pin_number)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -111,6 +147,18 @@ void TIMER1_IRQHandler(void)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
char send_buf[64];
|
||||||
|
|
||||||
|
printk("Hellowold 1!");
|
||||||
|
/*rc = uart_configure(uart0, &uart_cfg);
|
||||||
|
if (rc) {
|
||||||
|
printk("Could not configure device %s", uart0->name);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
snprintf(send_buf, 64, "Helloworld 2");
|
||||||
|
send_str(uart0, send_buf);
|
||||||
|
|
||||||
|
|
||||||
NVIC_EnableIRQ(TIMER1_IRQn); //enable timer1 interrupt
|
NVIC_EnableIRQ(TIMER1_IRQn); //enable timer1 interrupt
|
||||||
IRQ_DIRECT_CONNECT(TIMER1_IRQn, 3, TIMER1_IRQHandler, 0); //link interrupt flag to handler
|
IRQ_DIRECT_CONNECT(TIMER1_IRQn, 3, TIMER1_IRQHandler, 0); //link interrupt flag to handler
|
||||||
NVIC_SetPriority(TIMER1_IRQn, 3); //set interrupt execution priority
|
NVIC_SetPriority(TIMER1_IRQn, 3); //set interrupt execution priority
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue