SparkFun Forums 

Where electronics enthusiasts find answers.

Tips and questions relating to the GPS modules from SFE
By ant.innit
#179986
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:
Code: Select all

#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.
By ant.innit
#179992
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.
By bylos
#180174
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
By bylos
#180279
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.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]