LS20031 + Edison - GPIO

Hi.

I’ve been trying to hookup a LS20031 GPS to the Sparkfun GPIO Block for Edison. So far the GPS is blinking so i guess its doing ok when it comes to power and getting a lock. But I’m getting stuck on the Edison side, my c code so far is looking like this:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <errno.h>

#include <mraa.h>

void* handling_uart(void *arg) {
	unsigned char rbuffer[256];
	int *uart0 = (int *)arg;

	errno = 0;
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

	while(1) {
		pthread_testcancel();

		printf("going to try and read\n");
		read((*uart0), rbuffer, 256);
		memset(rbuffer, 0, 256);
		printf("\n read() %s\n", rbuffer);

		printf("read done. \r\n");
	}
}


int main(void) {
	mraa_uart_context uart_i;
	uart_i = mraa_uart_init(0);

	// not sure what mraa_uart_init is doing
	if(uart_i == NULL) {
		printf("failed to find uart\n");
	}

	int uart0 = -1;
	pthread_t thread;
	int ret, status;
	char serial_port[] = "/dev/ttyMFD1";

	uart0 = open(serial_port, O_RDWR, O_NONBLOCK);

	if(uart0 == -1) {
		printf("\n open() failed with error [%s]\n", strerror(errno));
		return -1;
	}

	struct termios options;
	tcgetattr(uart0, &options);

	cfsetispeed(&options, B57600);
	cfsetospeed(&options, B57600);

	options.c_cflag &= ~PARENB;
	options.c_cflag &= ~CSTOPB;
	options.c_cflag &= ~CSIZE;
	options.c_cflag |= CS8;

	options.c_cc[VTIME] = 0;
	options.c_cc[VMIN] = 0;
	options.c_lflag |= ICANON;

	tcflush(uart0, TCIFLUSH);
	tcsetattr(uart0, TCSANOW, &options);

	ret = pthread_create(&thread, NULL, handling_uart, &uart0);
	if(ret) {
		printf("\n pthread create failed with error [%s]\n", strerror(errno));
		return -1;
	}

	char c = getchar();
	status = pthread_cancel(thread);
	if(status) {
		printf("\n pthread cancel failed with error [%s]\n", strerror(errno));
		return -1;
	}

	close(uart0);

	return 0;
}

$ gcc -pthread -o uart uart.c -lmraa

I’m not sure if the serial is /dev/ttyMFD1, I have tried all the rest listed under ls /dev/tty*.

currently at a loss what i could be doing wrong.

it could all be wrong of course.

Just to expand a little regarding hookup, I have the GPIO 3.3v and GRD connected to the GPS, TX from GPS into RX on the GPIO.

I haven’t set anything on the Edison system, /dev/tty shows nothing new.

worked it out, need to enable the tx and rx pins.

Hi ant.innit,

I am also trying to use UART1 (ttyMFD1) from the Sparkfun GPIO block.

Data are successfully received on the RX pin, but when trying to write on port, TX pin stays at low level.

worked it out, need to enable the tx and rx pins.

Could you please be more specific ? I may have the same issue, but trying to play with /sys/kernel/debug/gpio_debug/gpio131 did not came to anything...

Thanks in advance,

Regards

I finally found the cause of my issues for TX and RX pins of UART1 :

It seems that the level shifter on the GPIO block is broken for the TX pin, as I can verify that the input voltage (Edison side) is 1.8V but the output voltage (header side) is 0V.