Main Site Documentation

ShiftIn and ShiftOut - Hitachi HM55B


#1

Ok, so I have a compass that works on ShiftIn and ShiftOut. I have looked all over to figure out how ShiftIn and ShiftOut works, and I have some good clues but nothing solid. Can anyone help? I have a feeling I am making this over complicated. It seems like it works like serial, but not quite.

The compass is the Hitachi HM55B from Parallax (http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/compass/List/0/SortField/4/ProductID/98/Default.aspx) The nice thing is they have example code in several languages on the page, however each example uses ShiftIn and ShiftOut. I would gladly write a driver to post if someone can tell me how this works.

I need this to work so badly. I have a robot that has no clue which way it is going.

Ben


#2

shiftin and shiftout are a horrible way to simulate SPI in software. FEZ has a hardware SPI support so there is no need to simulate anything in software.

The ebook explains SPI plus there are many examples online like this one http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

It would be really nice if you can make those functions and post them so beginners can benefit from your work :wink:


#3

Ok, so I think the SPI is going to work fine. Its not the best solution, but I dont want to bit bang it. The next problem I am running into is that my data coming back is broken into 11 bit sections. Yuck huh? So how do I turn the bytes I get back into bits that I can manipulate? I will include a shot from my logic analyzer this help illustrate what I am talking about. I am sure this is some simple low level byte manipulation some find easy… but I write business apps for a living, so I dont know how to do this in C#… and cant seem to find it on google.

BTW, someone else got this to work with SPI in C, so here is a link to their postings… the very last post is final code. http://forums.freescale.com/t5/16-Bit-Microcontrollers/HCS12-SPI-to-Digital-Compass-HM55B/m-p/43656

Logic shot: http://i922.photobucket.com/albums/ad65/wlinville/CompassLogicAna.png


#4

I would use a 16 bits integer which is ‘and-ed’ with this mask : 0000011111111111 (0x7FF)

Didn’t try it, though…


#5

Why not? because fo 11buts? Usually, processors never support 11 bit SPI. If your device (ADC maybe) send 11 bits, it will probably support 2 transfers of 8 bit or one 16 bit

You can bit bang if you like but that would be way too slow!!

This is how it is done

Read 2 bytes in an array (you can do it easier with 16 bit transfer but your device may not support it?)

int bit11= data[0];
bit11 <<=8;
bit11 |= data[1];

you may have to swap the bytes…such code is very very common in the embedded world but no usually seem on PC applications


#6

I have just looked at the compass datasheet and I can tell you this, the datasheet is very bad! They do not explain how to pack the data on 8-bit. I can see why you are having problems.

If this project is just for fun then maybe it is easy to just try and bit bang? To use SPI you would have to experiment since this is not explained in the (very bad) chip datasheet.


#7

Yah, thats the only reason I said SPI isnt the best solution… but I feel like I want it to work now. I have the tools I need… I just need to hook it to a basic stamp and use my analyzer, see what it puts out, and then start sending it stuff from SPI and see if I can replicate it. I dont mind bit banging it, in fact for the driver, this thing is so simple I was going to just hard code all the commands. I dont mind 4 bits… I did however want to learn more about SPI which I feel I have done.

Who knows, either way I will get it working and then post the driver. Its a nice compass, and I have found it to be a good asset. Next on the list is a driver for the PING module. See I have the Intro to Sensors pack from Parallax, and I need drivers for all the stuff. The first goal is to get my BoeBot to work exactly how it did with the BS2. Then I need it to out shine the BS2 by a mile. Thats why I wanted the 40 IO expansion board… I have a bunch of sensors I need running. Things like this Compass would work ok through the expansion board I would think… because I can bit bang it. Do you think I would be better off using a few FEZ boards rather than the expansion? I could buy a FEZ Mini for the same price and get a whole lot more for the money.


#8

Sensors are usually I2C or SPI and so they all can connect on the same wires. I would love to see an application where you need more than what you have on FEZ :smiley:

You have 2 SPI, an I2C, 4xUARTs…USB…many IOs :wink:


#9

Did I mention I have a habit of buying more than I really need? I generally only figure that out many years later… when I need something to level off the coffee table.