Hi everybody,
I want to receive data from a Loadcell Indicator throughout RS485. The LoadCell Indicator only send data to Micro chip. I also want my Micro chip communicate with the computer in both ways (transfer and receive) by RS232.
Can I do like that?
This is the first time I code for micro chip. I already try to use RS232, but with RS485 I do not have enough material to do. Please help me with any idea, useful links, papers or example codes.
I'm using T89C51AC2 micro chip and C in coding.
Thank you so much, Huy
Looks like that microcontroller has one UART, so it won't be real straightforward, but it should still be possible.
You'll probably need to add some glue logic and an I/O pin or two to switch your UART back and forth between the two ports. You'll probably need to add some kind of software logic to handle switching to the RS485 port in the middle of receiving data from the load cell, resulting in garbled data, which you'll have to ignore and then wait for good data to arrive.
If your PC initiates communication with your board, rather than the other way around, trying to share one UART with both ports is a little more trickier still. You'll probably have to add some kind of auto retry protocol to the RS232 port for the case when your PC tries to talk to your board, but the UART's connected to the RS485 port instead.
Having an RS485 device that transmits only seems odd, as it somewhat complicates having multiple devices on an RS485 bus, which is normally a common thing to do.
Good luck !!
"Looks like that microcontroller has one UART, so it won't be real straightforward"
Which begs the question: why choose a processor with only one UART, when plenty are available with two (or even more!)
Why make life difficult for yourself - especially as this is your first microcontroller project?!
It is possible to make a software UART - or, in this case, just a software receiver. Search for "Soft UART" or "software UART" and "bit-bang"
I can not count the posts I have seen over the years where the derivative has been selected <b.before the application was defined. Talk about "cart before the horse"
Erik
you post '89C51' which can be AT89C51, P89C51, something else or a generic name.
Ever so many posts have gone astray because the derivative name was not totally clear.
Yeah, This is exactly my first project with Micro. For all comments, I need time to understand them but I want to say thank you to all for your helps.
This is exactly my first project with Micro then i strongly recommend that you buy a SILabs devboard (F0xx, f1xx, f2xx - stay away from f3xx, f4xx and f5xx) it will give you ICE functionality which gives yo the ability to see everything that goes on inside the chip in real life, not 'simulated'
one more hint
there is, here, the Keil device database
http://www.keil.com/dd/parm_search.asp
it allow you to select 2 UARTs and get a list of all '51 derivatives with that.
"you post '89C51' which can be AT89C51, P89C51, something else or a generic name."
The title just said '89C51', but the body of the post did specify T89C51AC2.
:-)
Thank you Sirs,
But I am student, I bought this chip so I have to use this one. I think may be I can use another small chip to receive data from LoadCell and pass it to main chip by P0 and P2. (Actually, the loadcell has 19 bits, but I will cut 3 LSBs to get 16 bits)
(P1.3 is used to generate PWM, and P3.0 P3.1 are used for RS232 so P0 and P2 are free)
May I do like that?
"But I am student, I bought this chip so I have to use this one."
So, Hopefully, this is your first lesson learned: don't buy the chip until after you have determined which chip you need!
As Erik said, this is a classic example of "putting the cart before the horse".
Anyhow, if you're really stuck with it...
"I think may be I can use another small chip to receive data from LoadCell and pass it to main chip"
Yes, although that's an extra cost - check carefully that it won't work out cheaper to just go and buy a 2-UART 8051! And also consider your timescales to design it in - what is your deadline?
You can get external UART chips with parallel interfaces and also with SPI or I2C connections to the main processor. You could even use a 2nd, small, cheap, microcontroller...
Again, there's the soft-UART option...
Thank you all for your comments.
Huy