Page 1 of 1

RS232 with Nspire IO

Unread postPosted: 21 Mar 2016, 21:40
by santacruz
Hello,
I'm trying to communicate with my device via RS232. I'm running OS version: 4.2.0.532 and Ndless 4.2.0 cas cx

Initially I tried to communicate with LUA and the Asynchronous Serial Interface library with no prevail.

Next I installed ndless and downloaded the nspire io library.

I was having issues with the provided tests demo. When the code tried to write and save the file, I would get an ownership error. I removed this and now I have the following code.

Code: Select all
#include <os.h>
#include <nspireio/nspireio.h>


int main(void)
{
   assert_ndless_rev(874);
   clrscr();
   
   nio_console csl;
   nio_init(&csl,NIO_MAX_COLS,NIO_MAX_ROWS,0,0,NIO_COLOR_WHITE,NIO_COLOR_BLACK,TRUE);
   nio_set_default(&csl);
   nio_color(&csl,NIO_COLOR_BLACK,NIO_COLOR_WHITE);
   nio_puts("Nspire I/O testing tool\n");
   nio_color(&csl,NIO_COLOR_WHITE,NIO_COLOR_BLACK);
   nio_printf("Compiled %s %s\n",__DATE__,__TIME__);
   nio_puts("Press any key to flush console...\n");
   nio_drawing_enabled(&csl,FALSE);
   nio_putchar('A');
   nio_fputc('a',&csl);
   nio_putchar('\n');
   nio_puts("Color palette test:\n");
   int i, j;
   for(i = 0; i < 16; i++)
   {
      for(j = 0; j < 16; j++)
      {
         nio_color(&csl,i,j);
         nio_putchar('X');
      }
      nio_putchar('\n');
   }
   nio_color(&csl,NIO_COLOR_WHITE,NIO_COLOR_BLACK);
   nio_puts("This line is too long for the Nspire's screen so we have to continue it on the next line...\n");
   wait_key_pressed();
   nio_fflush(&csl);
   nio_drawing_enabled(&csl,TRUE);
   nio_puts("Enter text:\n");
   char input[100] = {0};
   nio_getsn(input,100);
   nio_printf("Your text was:\n%s\n",input);
   nio_puts("Enter a number: ");
   int num;

   nio_puts("Testing UART...\n");
   uart_puts("Nspire I/O testing tool\n");
   uart_printf("Compiled %s %s\n",__DATE__,__TIME__);
   
   uart_puts("Enter text: ");
   uart_getsn(input,100);
   uart_printf("Your text was: %s\n",input);
   
   
   nio_puts("Tests finished.");
   nio_free(&csl);
   wait_key_pressed();
   
   return 0;
}


I have my Nspire connected directly to my COM1 port via a 9 pin connector.

I start Putty listening to COM1 @ 115200 baud.
Data bits: 8
Parity: Even
Stop bits: 1
Flow control: None

When I run the test I get a string of nonsense, so this leads me to believe I have the wrong port settings. Does anyone know the correct settings?

Also when I look at the code I see uart_getsn(input,100);
Is this the serial port listening for input from the computer? When I execute the code it says "Testing Uart..." then straight to tests finished, shouldn't there be some type of pause there?


And on an unrelated note, how do I get the website to stay in English? It wants to change every time I reload a new page. I've tried the English flag in the upper right hand corner.

Re: RS232 with Nspire IO

Unread postPosted: 21 Mar 2016, 22:05
by Vogtinator
I have my Nspire connected directly to my COM1 port via a 9 pin connector

You're lucky that it still works! 12V from the D-Sub-9 connector is four times the voltage the calc accepts!
You need a level shifter to 3.3V.

And on an unrelated note, how do I get the website to stay in English? It wants to change every time I reload a new page. I've tried the English flag in the upper right hand corner.

Works for me here, I'm using Opera/Chromium/Blink/WebKit/KHTML.

Re: RS232 with Nspire IO

Unread postPosted: 21 Mar 2016, 23:29
by santacruz
I was only using pins 3,4, and 5. I measured and I was getting ~4V to ground.

I've moved everything to my Arduino and success!


Image

Re: RS232 with Nspire IO

Unread postPosted: 21 Mar 2016, 23:31
by Adriweb
Nice :D

FTR, Lua ASI is already working a little bit with some predefined boards, but will gain larger compatibility in the next update, as TI said :)

Re: RS232 with Nspire IO

Unread postPosted: 21 Mar 2016, 23:40
by Vogtinator
BTW: You should be able to do the same with stdout and stdin, either by "printf", "fwrite" or even c++ iostreams.

Re: RS232 with Nspire IO

Unread postPosted: 22 Mar 2016, 01:45
by santacruz
I'm trying to use uart_getsn to read data send from my computer and its not working too well.

If you look at the image above, I call uart_getsn after it prompts for "Enter text" and it won't take any user input. It will only print a previous string.

Is there a better method?