Simple rs232 rx not working

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys I have a small piece of code that is refusing to work for me.  It's a simple RS232 Rx byte.  The code is listed blow, hope someone can see something that I can't.

The small piece of code of interest is:

 

static void gps_comms_handler(uint8_t key)
{
	_putchar_test(key);
}
#include "rs232_port.h"

#define USART_ADDR USART1
#define USART_PINS PINS_USART1

static const struct _pin usart_pins[] = USART_PINS;

static struct _usart_desc usart_desc = {
	.addr           = USART_ADDR,
	.baudrate       = 115200,
	.mode           = US_MR_CHMODE_NORMAL | US_MR_PAR_NO | US_MR_CHRL_8_BIT,
	.transfer_mode  = USARTD_MODE_POLLING,
	.timeout        = 500, // unit: ms
};

static void gps_comms_handler(uint8_t key)
{
	_putchar_test(key);
}

static int _usart_finish_tx_transfer_callback(void* arg, void* arg2)
{
	usartd_finish_tx_transfer(0);
	return 0;
}

void _putchar_test(char character)
{
	struct _buffer tx = {
		.data = (unsigned char*)&character,
		.size = 1,
		.attr = USARTD_BUF_ATTR_WRITE,
	};
	struct _callback _cb = {
		.method = _usart_finish_tx_transfer_callback,
		.arg = 0,
	};
	usartd_transfer(0, &tx, &_cb);
	usartd_wait_tx_transfer(0);
}

int rx_test (void)
{
	/* Output example information */
	console_example_info("USART Example");

	/* Configure console interrupts */
	console_set_rx_handler(gps_comms_handler);
	console_enable_rx_interrupt();

	usartd_configure(0, &usart_desc);

	/* configure spi serial flash pins */
	pio_configure(usart_pins, ARRAY_SIZE(usart_pins));

	_putchar_test('*');
	while(1);
}

 

Last Edited: Mon. Mar 2, 2020 - 09:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just noticed there that there are two calls to console!  This is clearly wrong.

Anyone know what the calls should be to associate the interrupt with the comm port?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

try this in the morning:

static void _getchar_test(char character)
{
	struct _buffer rx = {
		.data = (unsigned char*)&character,
		.size = 1,
		.attr = USARTD_BUF_ATTR_READ,
	};
	struct _callback _cb = {
		.method = gps_comms_handler,
		.arg = 0,
	};
	usartd_transfer(0, &rx, &_cb);
	//usartd_wait_rx_transfer(0);
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no joy, anyone got a working example I could look at?