Connecting Arduino Uno to a Renesas M16C

Hi everyone,

My apologies in advance if I've posted this question in the wrong place.

I'm currently working on a project which involves the construction of an electronic compass. I'm using a Honeywell HMC5883L magnetometer (bought in breakout board form, from SparkFun), which should be easy enough to implement as plethoras of code exist across the internet.

However, my problem lies with the fact that I must use a Renesas M16C (62P variant) to interface between the host computer and the magnetometer. My question is, how easy would it be to connect the Arduino to the M16C, to act as an interface between the magnetometer and the host computer?

Hopefully that was coherent enough! I've included links to datasheets for both the M16C and the Honeywell HMC5883L. I really can't make heads or tails of the datasheets Renesas provide, as clearly, they've written it for the programmer who is more than competent with the logistics of I2C - which in case you haven't noticed, isn't me!

Thanks a bunch!

RyJ.

Honeywell HMC5883L: http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf

Renesas M16C62P I2C information: http://documentation.renesas.com/doc/products/mpumcu/apn/m16c/rej05b1349_m16cap.pdf

So you mean PC<-> M16C<-> Arduino <-> HMC5883L?

It means you need to know how to program two microcontroller architectures instead of one and also know how to get data between the PC to the M16C, which is easy enough with the Arduino (serial), but now you need to know how to do it with the M16C instead. Moving bytes between the Arduino and the M16C shouldn’t be hard, you can use SPI or bit bang them across a pair of GPIO lines, but, again, you need to know how to program the M16C to receive that data. In short, you are introducing a new microcontroller to your circuit, you need to know how to program it. I don’t think anyone here is going to figure that out for you, probably no one will even answer specific questions if you get to that point because very few people here work with Renesas controllers.

I’m sure you have your reasons, but there is a Rube Goldbergesque nature to what you are proposing here. You are using two microcontrollers where one is all that should be necessary and you have additionally chosen a microcontroller that has almost no hobbyist interest.

I must use a Renesas M16C

Whoever is requiring you to use the Renesas chip will probably not be very happy if you insert an arduino running net-public code to do the main work...

JoeN:
So you mean PC<-> M16C<-> Arduino <-> HMC5883L?

Exactly.

JoeN:
In short, you are introducing a new microcontroller to your circuit, you need to know how to program it. I don’t think anyone here is going to figure that out for you, probably no one will even answer specific questions if you get to that point because very few people here work with Renesas controllers.

I’m sure you have your reasons, but there is a Rube Goldbergesque nature to what you are proposing here. You are using two microcontrollers where one is all that should be necessary and you have additionally chosen a microcontroller that has almost no hobbyist interest.

Don’t get me wrong, I’m not asking anyone to do the work for me by any means. I just wanted to know how complex it would be. My reason for using the Arduino for direct communication with the magnetometer is simply due to the fact that doing so with the M16C is pain in the arse, to be frank.

Oh, I whole-heartedly agree with the M16C being uninteresting - it’s out of date, and very user-unfriendly. It is simply a requirement that I must use it as the main interface between the PC and the additional hardware I’m using. Believe me, it’s been causing hours, days, weeks of frustration.

Maybe the reason I’m having trouble with getting the M16C to retrieve data from the magnetometer is simply down to my (low, obviously) skill level. Maybe. But going any further with this trail of thought would make my posting on this forum irrelevant.

Thanks for your help!

RyJ94:
It is simply a requirement that I must use it as the main interface between the PC and the additional hardware I’m using. Believe me, it’s been causing hours, days, weeks of frustration.

Why is it a must to use that microcontroller? Is it a kind of homework?

mart256:
Why is it a must to use that microcontroller? Is it a kind of homework?

It is, yes. I understand people may not feel right about giving help on something that is assessed, but I'm just asking if anyone has an idea on where to start with extracting data from the Arduino via the M16C. I've no idea where to begin!

RyJ94:
It is, yes. I understand people may not feel right about giving help on something that is assessed, but I'm just asking if anyone has an idea on where to start with extracting data from the Arduino via the M16C. I've no idea where to begin!

Well, look, GPIO is the easiest thing in the world. If you don't want to get to understand how SPI or I2C works on the Renesas then all you need to do is learn GPIO, how to read if input pins are at 0 or 1 and set output pins at 0 or 1. Knowing how to do this on both the Renesas and the Arduino allows you to roll your own scheme on how to get data across. For example, you could have three lines between the Arduino and the Renesas, two are input on the Renesas and one is output and the other way around on the Arduino. Let's call them READY (output on Arduino), DATA (output on arduino), CLOCK (output on Renesas). When the Arduino has a measurement to send, it raises READY from 0 to 1. The Renesas is tightly polling this GPIO pin and when it sees the line goes to 1 it clears out the old value and then raises the CLOCK line and lowers it whatever number of times the bit size of the reading is. The Arduino sees the CLOCK line go high and puts the next bit of the data to be transferred on the DATA line. It lowers the READY line after the last bit has been placed on the DATA line. The Renesas reads the DATA line in after it raises and lowers the CLOCK line and waits perhaps a ms to give the Arduino a chance to set the DATA line correctly. This is not normally how this is done, you would use SPI, but if you only know GPIO this would be an easy enough way to transmit the data across in a serial format. And if you have enough extra GPIOs you could do it all at once with a parallel transfer. I'm not sure this is what your instructor wants to see, though, it would be considered unartful.

Given the choice between "learn how to use I2C and the HMC5883L on the M16" and "design and implement an inter-processor communications link between M16 and Arduino", I would think that the first would be easier. On the plus side, even if the arduino code can't be used directly, it's probably a reasonable example of how to talk to the HMC. Just replace the low-level I2C calls and convert to C instead of C++...

JoeN:
Well, look, GPIO is the easiest thing in the world. If you don't want to get to understand how SPI or I2C works on the Renesas then all you need to do is learn GPIO, how to read if input pins are at 0 or 1 and set output pins at 0 or 1. Knowing how to do this on both the Renesas and the Arduino allows you to roll your own scheme on how to get data across. For example, you could have three lines between the Arduino and the Renesas, two are input on the Renesas and one is output and the other way around on the Arduino. Let's call them READY (output on Arduino), DATA (output on arduino), CLOCK (output on Renesas). When the Arduino has a measurement to send, it raises READY from 0 to 1. The Renesas is tightly polling this GPIO pin and when it sees the line goes to 1 it clears out the old value and then raises the CLOCK line and lowers it whatever number of times the bit size of the reading is. The Arduino sees the CLOCK line go high and puts the next bit of the data to be transferred on the DATA line. It lowers the READY line after the last bit has been placed on the DATA line. The Renesas reads the DATA line in after it raises and lowers the CLOCK line and waits perhaps a ms to give the Arduino a chance to set the DATA line correctly. This is not normally how this is done, you would use SPI, but if you only know GPIO this would be an easy enough way to transmit the data across in a serial format. And if you have enough extra GPIOs you could do it all at once with a parallel transfer. I'm not sure this is what your instructor wants to see, though, it would be considered unartful.

Ultimately, the main purpose of this little 'project' that I'm doing is to exercise all the ins and outs of the concept of group-working to solve a problem. The fact that it involves microcontrollers and C programming is to simply give this group work an engineering context, so the semantics of the programming probably isn't of great importance, since the level of coding we require to solve this problem is so tremendously out of scope of any of our previous microcontroller programming classes.

I can grasp what you're saying here though, it makes sense. Thanks for taking the time to help me out.

RyJ.

westfw:
Given the choice between "learn how to use I2C and the HMC5883L on the M16" and "design and implement an inter-processor communications link between M16 and Arduino", I would think that the first would be easier. On the plus side, even if the arduino code can't be used directly, it's probably a reasonable example of how to talk to the HMC. Just replace the low-level I2C calls and convert to C instead of C++...

Oh exactly. This was what I originally had in mind. Look at some example of programming an Arduino to control the HMC5883L and grasp some form of understanding of it - then implement this into C for use with the M16C. Annoyingly, the Arduino has access the wire.h library (specifically for Arduino), which makes programming the damn thing so much easier. I know it isn't meant to be easy, and that it's not going to be a case of any brain-dead idiot can just copy code from somewhere else and use it, but like I said - we're in a little over our heads.

We haven't actually bought an Arduino yet, for the record. This was just an option I wanted to explore.

Thanks for your help! I appreciate you taking your time.

RyJ94:
I know it isn't meant to be easy, and that it's not going to be a case of any brain-dead idiot can just copy code from somewhere else and use it, but like I said - we're in a little over our heads.

Actually, that is basically the idea behind Arduino - to make programming a microcontroller as easy as possible, and to make it actually easy, if possible. Children are programming microcontrollers now because of Arduino. I think Arduino does this very, very well. In fact, the Arduino abstraction layer of C libraries is fairly portable and has been ported to other microcontroller architectures (ARM, PIC, x86 for sure, maybe others as well for all I know). If someone had bothered to do this with Renesas, that would help a person like you quite a bit. But I don't think anyone has. Renesas just does not have much mind share in the hobby community.

JoeN:
Actually, that is basically the idea behind Arduino - to make programming a microcontroller as easy as possible, and to make it actually easy, if possible. Children are programming microcontrollers now because of Arduino. I think Arduino does this very, very well. In fact, the Arduino abstraction layer of C libraries is fairly portable and has been ported to other microcontroller architectures (ARM, PIC, x86 for sure, maybe others as well for all I know). If someone had bothered to do this with Renesas, that would help a person like you quite a bit. But I don't think anyone has. Renesas just does not have much mind share in the hobby community.

You're right, and I'd imagine that's why we are being forced into using the Renesas microcontroller - because it's so unfriendly that successful programming of the damn thing would require a level on ingenuity and 'thinking outside the box'. Drat.

Not to mention the fact that the particular Renesas microcontroller I'm using is about 11 years old..

It looks to me as though the M16/62P has I2C as a sub-mode of its UARTS, so all you have to do is figure out how to implement the "Wire" API on the M16 UARTs, and you should be in good shape. "Wire" (probably) provides a good example of functions that make an I2C interface easy to use from the "upper" levels of a program.
(every once in a while you get what LOOKS like a reasonable interface, but it turns out that it's very specific to the way a specific chip implements things. :frowning: ) (Are you programming "bare metal" M16, or are you using some specific set of libraries?)

I really hate Renesas datasheets. I've picked up several free renesas development boards, always on the basis that they sound really nice, and I get stuck in the documentation. Not to mention that the architecture seems sorta ugly. Z80 with add-ons. Sigh.

OTOH, the ATmega48 is similarly "old". The m328p on arduino has some more modern bits (more memory, "picopower"), but the I2C peripheral is the same...

westfw:
It looks to me as though the M16/62P has I2C as a sub-mode of its UARTS, so all you have to do is figure out how to implement the "Wire" API on the M16 UARTs, and you should be in good shape. "Wire" (probably) provides a good example of functions that make an I2C interface easy to use from the "upper" levels of a program.
(every once in a while you get what LOOKS like a reasonable interface, but it turns out that it's very specific to the way a specific chip implements things. :frowning: ) (Are you programming "bare metal" M16, or are you using some specific set of libraries?)

I really hate Renesas datasheets. I've picked up several free renesas development boards, always on the basis that they sound really nice, and I get stuck in the documentation. Not to mention that the architecture seems sorta ugly. Z80 with add-ons. Sigh.

OTOH, the ATmega48 is similarly "old". The m328p on arduino has some more modern bits (more memory, "picopower"), but the I2C peripheral is the same...

Yeah, I think that if I want to have any hope of accomplishing this, I'll have to sort of retrofit the wire.h library to the M16C. Renesas do make an attempt at providing some functions for reading/writing to and from the I2C bus, but it's pretty convoluted and doesn't work (for me). Regardless of my skill level, Renesas documentation is very unhelpful - Renesas customer support don't even want to help either, any attempts I've made at contacting them for help have been met with uninterested replies. Probably because the board is 10 years out of date. I hate them for it.