Jump to content

serial communicate


v_pan

Recommended Posts

hello ...

i'm trying to communicate from my microcontroller

to send a simple printf() ,but i have problem's

1. i have an error (-1073807298 ) but i don't understand what it is .I searched at the Visa error codes

and the error says "Could not perform operation because of I/O error".

i'm still confuse about this

2. even with error label read buffer takes some data but it isn't the data which i send from microcontroller

for example i send printf("abcd\n");

and the read buffer has different value!!

(i tried the same C code to hyperterminal and everything was fine)

what's going wrong?

thank you...

Link to comment

QUOTE (v_pan @ Oct 18 2008, 05:00 PM)

for example i send printf("abcd\n");

....and the read buffer has different value!!

what's going wrong?

Hello V,

I re-wired your example to utilize dataflow using the error cluster. We want to setup -> flush -> read -> close, in that order. I put the read VI in a while loop so we will read continuously at the interval set by timeout.

Try the updated example and we can go from there.

~Dan

Link to comment

thank you for your answer Dan DeFriese

i do a simple example to verify that the character

i send from microcontroller will

present at read buffer

my c code is

while(!input(button)){

delay_ms(100);

printf("a\n"); }

everytime i press the button i want to see in "read buffer"

character 'a'

but i see differents character's everytime i press the button

the right thing will be to see all time 'a'

where do you think the wrong is?

and something else

when i increase the "bytes to read" (2,3,4....)visa error appears "blinking"

when i have it constantly at 1 byte it's ok but visa error appears continually and does not appear the "a"

as you can see at example

(ps. over hyperterminal works fine)

i hope you to understand what i mean...

thank you...

Link to comment

We've got past the first hurdle..no more IO error. The error I see here is timeout, which is what we expect (once a second, unless we're sending correct #number of bytes to it). Guess what, if you send more than what's expected... you'll get the "might be more data error code" ... We'll get to that later.

So the next question is why are we interpreting the data incorrectly. Can you post your hyperterminal setup. What about the the UART setup code for the micro.

My first suspect is the is that the number of bits or stop bits in the word are not equal between the transmitter and receiver. This would result in differenent data seen each time. This would normally result in parity error but not when have parity set to none.

Also, since your micro is sending a newline character you can play the Send Term Char and Enable Term Char controls in the example VI.

~Dan

P.S. If your using an Atmel AVR let me know?

Link to comment

Thank you very much for your help.

This programme works fine by now. You may notice that I made a modification to your

programme. Instead of showing a character i made it to show a number.

One problem that now appears is that when I am going to send some bytes every little time

lets say every 1ms the programme confuses and it shows wrong values.

Can you think something to solve this problem????

What I want to do is a 12-bit ADC convert from my microcontroller and represent this bits

as a number to a figure. Is that programme good or I have to make another one ?

Link to comment

QUOTE (v_pan @ Oct 20 2008, 03:48 PM)

Instead of showing a character i made it to show a number.

One problem that now appears is that when I am going to send some bytes every little time

lets say every 1ms the programme confuses and it shows wrong values.

Can you think something to solve this problem????

What I want to do is a 12-bit ADC convert from my microcontroller and represent this bits

as a number to a figure. Is that programme good or I have to make another one ?

Before I invested in making creating a binary protocol. I would keep it simple and transmit ASCII. For example:

int_16 adc_value = 0;

...

while (PRESSED == GetButtonState()){

adc_value = ReadADC();

printf ("ADC Value: %d\n", adc_value);

sleep(some_time);

}

Verify that your reading data correctly using Hyperterm:

ADC Value: 12345

ADC Value: 12345

ADC Value: 12345

ADC Value: 12345

ADC Value: 12345

ADC Value: 12345

In LabVIEW, experiment with with my previous example (try enabling the termination character with the char set to 0x0A "\n"). Also make sure that the #bytes your're reading is greater than whats being sent (>17).

Once your syncronized and getting the correct data use the Scan From String primitive located on the string function palette to convert the numeric back to decimal (the scan string should be "ADC Value: %d"). This value can then be used as the input to the chart.

I'll try sending an example when I have more time.

Link to comment

i was sending over hyperterminal that you was wrote and worked fine

i did not putted delays and program did not confused

i didn't maked "scan from string "work.

i noticed that when i had labview and C code delay 10ms works fine.(and #byte read at 20)

now another problem that generate is how represent negative numbers!

i sent int lut[6]= {10 20 30 -20 -10 }

for(i=1,i<=5 i++){

printf("%d \n",lut)}

..........................

10 20 and 30 plotted

-20 -30 not!!

can i fixed it on labview or can i try to fixed it on C code?

what is your opinion?

Link to comment

i made some changes in VI and now seems to work!

represent and negative numbers!

(for some reason cannot upload .bmp to see it)

this is for one signal

I want to use cases so as to saperate 2-3 signals.

For example, when I sent from the serial "A30"

the programe will recognise that the number 30

have to store to the first file.

When I sent "B45" the programme will store the

number 45 to the second file etc.

I have done a similar programe to recognise numbers,

not srings.

Can I do that?

any idea?

Link to comment

QUOTE (v_pan @ Oct 22 2008, 03:42 PM)

I want to use cases so as to saperate 2-3 signals.

For example, when I sent from the serial "A30"

the programe will recognise that the number 30

have to store to the first file.

When I sent "B45" the programme will store the

number 45 to the second file etc.

I have done a similar programe to recognise numbers,

not srings.

Can I do that?

any idea?

Yes, see the updated example. I've create a simple stub to simulate what "should be coming from your uC.

Link to comment

i'm not so sure if i have done the right changes

i think that i have done wrong connections :wacko:

when it's runs the case loop (that represent A,B,C plots) is always "0"

and i don;t see nothing plotting!

but i noticed "read buffer" takes the right values .

printf function from pic

printf ("A%d\n",lut);

printf ("B%d\n",lut1);

printf ("C%d\n",lut2);

what have i done wrong?

thanks Dan DeFriese for your significantly help!!

Link to comment

QUOTE (v_pan @ Oct 23 2008, 03:55 PM)

i think that i have done wrong connections :wacko:

when it's runs the case loop (that represent A,B,C plots) is always "0"

printf function from pic

printf ("A%d\n",lut);

printf ("B%d\n",lut1);

printf ("C%d\n",lut2);

what have i done wrong?

Looks like a simple whitespace problem... a few extra in the VI and none in the pic.

In order for the Scan From String primitive to work it will need to see two distinct strings (e.g. A<space>123).

example:

printf ("A%d\n",lut);

// becomes

printf ("A %d\n",lut); // notice the space between 'A' and '%d'

Likewise, the format string input to Scan From String in LabVIEW should compliment this with: "%s %d" as in the example.

Play with Scan From String in a blank VI and use the LabVIEW help to get a good feel for this function as well as its compliment Format Into String... These are extremely useful.

~Dan

Link to comment

QUOTE (v_pan @ Oct 24 2008, 04:58 PM)

Glad to hear it!

QUOTE (v_pan @ Oct 24 2008, 04:58 PM)

However, the minimum delay that it works correctly is at 5ms.

If I need to reduce it what I have to do;(e.g 10,100us).

At this point (assume 9600 baud) requires ~1 ms per byte (1/9600 * 10). Now, if worst case we send "A -4096/n" or 8 bytes ("/n" is 1 byte) then 8 ms is the fastest interval you can transmit (evidently, your dac processing is consuming 3 ms for a delay of 5 ms to continue to function). If you set the baud rate to 115K then, in theory, you could send messages at ~800 uS interval. If you move to a binary protocol you could transfer all three dac values using 5 to 6 bytes including a header, data, and checksum. However, before building such a VI you should become familiar with state-machine implemenation in LabVIEW. Also, I recommend reading Serial Port Complete by Jan Axelson if possible. (Though, I think his USB Complete kinda stinks.)

Anyway, best of luck and happy wiring :rolleyes: .

~Dan

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.