Tuesday, 9th of March 2010
Tuesday, 9th of March 2010
"robostix" — 5 posts
I want to connect the gumstix to the gpsstix and the robostix....hmmm....we'll if I connect the gpsstix to the gumstix in the stack, then I can talk to the robostix via I2C using David Hyland's great i2c programs. There are a set of i2c pins exposed on the gpsstix, so I soldered 0.05" headers to those pins and will use the robostix's i2c 0.1" pins (the SDA and SCL are on the UARTS connector).

The robostix's i2c lines run at 5v and the gumstix run at 3.3v, so I need to shift bidirectionally. Maxim sells a bunch of chips to do this. I'm using the Maxim 3378 (datasheet). The Max3378 is bidirectional and accepts +1.2v to +5.5v on the low side and +1.65v and +5.5v on the high side. Obviously, I don't need 4 lines for the i2c bus, but I think I might find uses for the other ones. in the TSSOP package. I mistakenly ordered the UCSP package first, man that is a small chip.



Well, I'm not that good at soldering, so I'm using the TSSOP with the Spark Fun SSOP to DIP Adapter (SKU#: BOB-00498).

Here you can see the diagram from the datasheet and here it is on the breakout board.



I have connected up leg 1 on the chip to pin 1 on the breakout board.

According to the datasheet, Vl is the low voltage side (3.3v in my case) and Vcc is the high voltage side (5v). You apply a reference voltage to pin 1 and pin 14.

Image ©Maxim

On the Robostix, the i2c pins are on the UART section. The pinouts are:
10: Ground
12: SDA (labeled TX)
14: Vcc (5 volts)
16: SCL (labeled RX)
SDA and SCL are both 5v logic levels and have 10k pullups to +5.

On my test board I have SDA connected on Vcc1 and Vl1 and SCL connected on Vcc2 and Vl2. I have a 0.1uF cap on both Vcc and Vl and 1uF cap on the Vcc as per the datasheet.

Plugged it all together and it worked! It seems that I have to boot the gumstix first and then the robostix. If I turn off the robostix and then back on while the gumstix is already booted, it also didn't work. Have to look more at this.


Wired up a toggle switch to the robostix in the following manner:


GPIO----------switch--------------GND
|
|------------10k resistor--------Vcc


I have the switch on port c.7 and set the direction to in.

Switch is open
# i2c-io 0x0b getdir c.7
in
# i2c-io 0x0b get c.7
0

Switch is closed
# i2c-io 0x0b get c.7
1
Dave Hylands has written a great little program to read GPIO and ADC pins on the robostix from the gumstix. There are several commands.

Info Retrieves information about the robostix program
Get port.pin Retrieves the value of a pin
Set port.pin val Sets the value of a pin
SetDir port.pin dir Sets the direction of a pin
ReadReg regIdx Reads an 8 bit register
WriteReg regIdx val Writes a value into an 8 bit register

If a GPIO pin is set for input:
1 : pullup resistor enabled
0 : pullup resistor disabled

if a GPIO pin is set for output:
1 : 5v
0: 0v

To turn on the blue LED on the robostix:
i2c-io 0x0b setdir g.3 out
i2c-io 0x0b set g.3 0


and to turn if off:
i2c-io 0x0b set g.3 1
I setup the MaxBotix MaxSonar-EZ1 today onto AD0. The only problem I had was reading the results. You set the dir using f.0 but you read adc.0 to get the information from the sensor.

for example:

i2c-io 0x0b get adc.0
to read the sensor's output

i2c-io 0x0b setdir f.0 in
to set the sensor for input

The sensor seems to read fine.

I'm taking the value and multiplying it a bit to get an output in inches:
round((($adc0*2.65/1024) * 100) * 2);

Here is the whole microperl script:
#!/usr/bin/microperl

# setup
$s = `/sbin/i2c-io 0x0b setdir f.0 in`;
$s = `/sbin/i2c-io 0x0b set f.0 off`;

while(1) {
$adc0 = `/sbin/i2c-io 0x0b get adc.0`;
#print "$adc0";
$dist = round((($adc0*2.65/1024) * 100) * 2);
print "$dist\n";
}

sub round {
my($number) = shift;
return int($number+.5);
}
Followed instructions on:
http://docswiki.gumstix.com/I2c

I used the precompiled sources.

You have to get the i2c bootloader working on the robostix first and this requires that you get an ISP or the gumstix ISP setup (see post). See this wiki entry.

the you can install i2c-Boot-m128-16MHz.hex
uisp --wr_fuse_l=0xbf --wr_fuse_h=0xc2 --wr_fuse_e=0xff (the fuses only need to be set once)
uisp --erase --upload if=i2c-Boot-m128-16MHz.hex

the red LED should start flashing if all went well.

You then need to get i2c-load setup on the gumstix. I downloaded a compiled version from here.
(which is the correct one for my version).

Worked like a charm. running the info command I get:
# ./i2c-load --reset 0x0b info
I2C Dev Addr: 0x0b
Version: 1
MinVersion: 1
Part Number: 0x9702 (ATMega128)
Reg Size: 256
RAM Size: 4096
EEPROM Size: 4096
Page Size: 256
Flash Size: 128k
Node Name: not set
Boot Delay: unset, defaults to 5 seconds
I2C Addr: unset, defaults to 0x0b


Now with i2c-load you can download programs to the robostix.
put on code from:
http://docswiki.gumstix.com/Robostix_gumstix_ISP

You can use the gumstix to download files into the robostix flash. Create a jumper which connects Atmel 0 Tx to PXA ST Rx and Atmel 0 Rx to PXA ST Tx on the Robostix. It is the jumpers in the section labeled UARTS near the 60-pin hirose connector. I used an old IDE cable and wired in some jumpers; ugly but works.

# insmod robostix_drv.ko (to remove use rmmod robostix_drv.ko)
# ./uisp
Atmel AVR ATmega128 is found.

Yoohoo!

Now added the robostix driver to /etc/modules.

mkdir /lib/modules/2.6.18gum/kernel/drivers/robostix/
mv robostix_drv.ko /lib/modules/2.6.18gum/kernel/drivers/robostix/
insmod
/lib/modules/2.6.18gum/kernel/drivers/robostix/robostix_drv.ko
depmod -a
modprobe robostix_drv

then added:
# Driver for robostix control
robostix_drv

to /etc/modules

set the fuses on the robostix:
# uisp --wr_fuse_l=0xbf --wr_fuse_h=0xc9 --wr_fuse_e=0xff
Atmel AVR ATmega128 is found.

Fuse Low Byte set to 0xbf

Fuse High Byte set to 0xc9


Fuse Extended Byte set to 0xff


Next, I downloaded the test LED flashing program to see if all went well:
# uisp --erase --upload if=Flash-LED.hex
Atmel AVR ATmega128 is found.
Erasing device ...
Reinitializing device
Atmel AVR ATmega128 is found.
Uploading: flash


yes! flashing LEDs....looking good.