Can't find UART output


#1

Hello All,

I am attempting to output data to the UART-1 Port but I can’t see any output. I am using Uart-1 because this port should by default be connected to IoT Connector #0. From what I see on the schematic I should see the output on pins 12 and 13. This translate to column P3 the inner column and row 2 and 3.

P2       P3 

29 10 | 11 28
30 09 | 12 27
31 08 | 13 26
32 07 | 14 25
33 06 | 15 24
34 05 | 16 23
35 04 | 17 22
37 03 | 18 21

I have set the UART to run the customer linux application:
microcom -E /dev/ttyAT
AT!MAPUART=17,1

But with all this I still can not see any output. I have included my code below, it is an adaptation from timerLed.

 int open_port(void)
{
  int fd; /* File descriptor for the port */
  fd = open("/dev/ttyHSL1", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1)
  {
  /*
  * Could not open the port.
  */
    perror("open_port: Unable to open /dev/ttyHSL1 - ");
  }
  else
     fcntl(fd, F_SETFL, 0);

  return (fd);
}

//--------------------------------------------------------------------------------------------------
/**
 * Main program starts here
 */
//--------------------------------------------------------------------------------------------------

COMPONENT_INIT
{
LE_INFO("===============blinking LED application has started");

ConfigureLed();
//TODO: All code gets run from here:
int uart_fd = open_port();
int n = write(uart_fd, "ATZ\r", 4);
if (n < 0)
    fputs("write() of 4 bytes failed!\n", stderr);

LE_INFO("=====================================================");
LE_INFO("=====================================================");
LE_INFO("=====================================================");
LE_INFO("Attempt to output to UART produces: %d", n);
LE_INFO("=====================================================");
LE_INFO("=====================================================");
LE_INFO("=====================================================");

le_timer_Ref_t ledTimerRef = le_timer_Create("LED Timer");
le_timer_SetMsInterval(ledTimerRef, LED_SAMPLE_INTERVAL_IN_MILLISECONDS);
le_timer_SetRepeat(ledTimerRef, 0);
le_timer_SetHandler(ledTimerRef,ledTimer);
le_timer_Start(ledTimerRef);

}

In my adef I have included:

requires:
{
    device:
    {
         [rw] /dev/ttyHSL1 /dev/ttyHSL1 
    }
}

Any help would be very much appreciated.

Thanks
Kas


#2

I should also mention that if I try use HSL0 instead of HSL1 the program will not run. When I try manually start the program I get a message “Application ‘timerLed’ is not installed”. I can remove the program but trying to install it again produce teh same results.

I have tried with sandbox set to both true and false with no difference in the result.

Anyhelp would be great.
Kas


#3

Hi @Kas.Lewis

HSL1 is UART 2 (defaults to Linux console). You’re after HS0 (not HSL0) - a bit confusing I know.

Change to this in your .c file.

  fd = open("/dev/ttyHS0", O_RDWR | O_NOCTTY | O_NDELAY);

And add this to your .adef file

        // Get read and write access to the UART1 port.
        [rw]    /dev/ttyHS0   /dev/ttyHS0

Lastly, you may also need to enable UART 1 on IoT#0 using the muxCtrlService (from your app) or the mux command line tool. I believe the command is mux 1

Cheers,
Raf


#4

Hello @Raf,

I have tried HS0 as you suggested but I still don’t see any output. With regards to using the mux I’m not 100% sure how to do that. I will see if I can find anything on the forums to help with that.

I do have another question. On page 27 of the Developers Guide, it seems to show the default connection from UART1 is to IoT connector #0. If my understanding is correct I should see an output on the IoT breakout board without changing the mux settings.

Thankfully
Kas


#5

Hi @Kas.Lewis

One thing I noticed in your code is that you never set the port attributes after opening it. I.E. baud rate, mode (raw or canonical), flow control. Though I suspect the lack of output has more to do with the mux settings.

Here’s a snippet of code I’ve used to run a serial port @ 115200 baud in ‘raw’ mode which you can use to get you started:

int SetPortSettings(int fd)
{
	struct termios tp;
	int ret;

	ret = tcgetattr(fd, &tp);			// get the current settings before modifying them
	if (ret < 0)
	{
		perror("tcgetattr");
	}

	cfsetspeed(&tp, B115200);			// 115200 baud
	cfmakeraw(&tp);						// raw mode

	tp.c_cc[VMIN] = 0;					// non-blocking reads
	tp.c_cc[VTIME] = 5;					// 5x 10ms inter-character timeout

	tp.c_cflag &= ~CSTOPB;
	//tp.c_cflag &= ~CRTSCTS;    		// HW flow control OFF
	tp.c_cflag |= CRTSCTS;    			// HW flow control ON
	tp.c_cflag |= CLOCAL | CREAD;

	ret = tcsetattr(fd, TCSANOW, &tp);	// set the new settings
	if (ret < 0)
	{
		perror("tcsetattr");
	}

	ret = tcflush(fd, TCIOFLUSH);		// flush i/o buffers
	if (ret < 0)
	{
		perror("tcflush");
	}

	return ret;
}

Check out these two links for more info on configuring port settings:
https://www.cmrr.umn.edu/~strupp/serial.html#2_54
http://www.tldp.org/HOWTO/text/Serial-Programming-HOWTO2

It’s true that the default connection for UART1 is on IoT#0 (dip switch 6 on SW401). However, I also found that it was necessary to explicitly enable UART 1 on IoT#0 from the mux control app. It was my experience after running my own test out of curiosity. I was able to get an output on IoT#0.

Here’s a quick test you can run from the command line while ssh’d into the mangOH without the need for an app to confirm UART operation:

  1. ssh into mangOH
  2. type the command: mux 1
    this enables UART1 on IoT slot 0
  3. type the command: stty -F /dev/ttyHS0 -cooked
    this sets /dev/ttyHS0 to ‘raw’ mode (uncooked)
  4. type the command: microcom -E /dev/ttyHS0 -s 115200
    this opens /dev/ttyHS0 @115200 baud
  5. start typing characters and you should observe the data on the IoT UART pins

If you still don’t see any output, try changing the position of dip switch 6 on SW401.

See how you go with this.

Cheers,
Raf


#6

Hello @Raf,

I have tried the quick test you mentioned but have had no luck:

I used a scope on the IoT board looking at the pins mentioned. I also looked at CN600 pin 7. I moved SW401 switch 6 both on and off and still no success. IF there are any further suggestions I would be happy to hear them.

Thanks
Kas


#7

Hi @Kas.Lewis

Sorry to hear that didn’t work for you.
Did you get a ‘Success’ message when executing mux 1?

Note that you should be looking on Pin 9 at CN600 for output from the modem.
Similarly, look on the pin labeled RXD on the IoT pin-out the image above.

The labels on the schematic refer to the client-side (not the modem), I.E. from the perspective of a device connected to the modem. So, RX is actually the devices receive line (modem’s transmit line) and vice-versa.

Also, you probably already know this, but the voltage levels are 1.8V. Set the scope to trigger accordingly (falling-edge).

Raf


#8

Hi Kas,

Can you open an at port and run at!mapuart? command?

Regards,
Ashish


#9

Hello @asyal,

Results from running the command are:

root@swi-mdm9x15:~# microcom -E /dev/ttyAT
at!mapuart?
!MAPUART: 17,16

OK

Kas


#10

Ok, you’re settings look ok. Did you check as Raf as asked on pin 9 of cn600?


#11

I did try looking at all the pins on CN600 previously with a scope. I don’t recall seeing anything when using microcom. When running my code I saw something but maybe only 2 bytes, not the 4 that I am sending (“ATZ\r”).

Looking at Raf’s comment my understanding is that I cannot use a CP2102 serial to USB adapter. The CP2102 needs a logic high > 2.00V but the mangOH outputs a high of 1.8V. If you could confirm my understanding that would be helpful.

Kas


#12

you can use a cp2104 (1.8V IO) serial to usb adapter not cp2102.


#13

Hello @asyal, @Raf,

Above is a screenshot from my testng. During this testing I had my scope connected to the IoT breakout board at the TXD and the RXD and nothing was detected on either line (The slope was set to 1V/Div, Horizontal 1s/Div).

It appears the issue is the two fold. Firstly my scope does not have a high enough resolution display (TBS 1202B-EDU). So while I was hoping to see some spikes even on a low resolution (large time base) the display could not display them. Moving to a smaller time base (25us/Div) and using the trigger I was able to capture the serial data. Also attaching my logic analyzer (Saleae Original Logic) I was able to capture everything. The captured data includes the output from the program even without any setup (Default is 9600 baud).

The second issue is the logic levels. Using a CP1202 or other serial to USB converters I was expecting levels of > 2.0V for a high. Knowing now that I need a converter that can read a logic high of 1.8V the regular serial to USB converters will give you a false negative. They will insist no data has been received because in fact the logic levels they require where not met. Moving to a CP1204 as @asyal suggests would resolve this issue.

Hopefully I can keep moving forward for full communication over UART. BTW is there anyway to change the logic levels, on the MangOH board without using an external level shifter.

Thanks
Kas


#14

Hi @Kas.Lewis

Good to see the issue has been isolated. I too use a Saleae Logic analyzer for all my debugging. I swear by them - they’re a great tool and have saved me many countless hours of head banging/scratching.

I don’t believe there is a way change the logic levels on the WP8548 GPIO. You’ll need the external hardware level shifters.

Are you wanting to communicate with a PC over UART from mangOH?
You could enable User Linux Application mode on UART2 (you’d lose the console ability, though).

microcom -E /dev/ttyAT
AT!MAPUART=17,2

UART2 (/dev/ttyHSL1) has a RS-232 Transceiver IC. You could plug the DB9 straight into a PC or use a USB to RS-232 adaptor cable.

If anything, it might serve as means to get your program working, then switch over to /dev/ttyHS0 once you resolve the level shifting.

Cheers,
Raf


#15

Thank you both @Raf and @asyal for you help it has really helped me move along.

I am trying to talk to an MCP39F511 from Microchip. The idea is to monitor power consumption and then upload the data to AirVantage. As I cannot yet use AirVantage (wrong SIM card, Freedom Mobile AKA Wind Mobile doesn’t work with the module) I am starting here and hopefully will be able to use WiFi to talk to Airvantage later or I’ll borrow a SIM for a while to get that portion working.

Thanks
Kas