I2C help for Olimex MOD-TC-MK2-31855

jikmar

New Member
I'm having trouble connecting this to my Picaxe 40X2

The idea of the MOD-TC-MK2-31855 board is that it interfaces between a thermocouple and an i2c compatible microcontroller. It has 2 chips on the board, a MAX31855 (to amplify the thermocouple voltage and provide cold-junction compensation, and a PIC16F1503 to convert to various protocols including i2c.

The following is from the MOD-TC-MK2-31855 documentation...

Code:
* GET_TEMP(0x21):
		Read the data that comes directly from MAX31855. Make sure to read MAX31855 datasheet to decode the data.


	Example:
	--------
	START | ADDRESS | W | ACK | GET_TEMP | ACK | STOP | START | ADDRESS | R | ACK | DATA0 | ACK | DATA1 | ACK | DATA2 | ACK | DATA3 | NACK | STOP
	
	where:
			ADDRESS = 0x23 (the default address)
			GET_TEMP = 0x21
			DATA0, DATA1, DATA2, DATA3 - The 32 bits of data that comes from MAX31855

In pseudo code:
		
	StartI2C();
	WriteBYte((address << 1) | WRITE);
	CheckAck();
	WriteByte(GET_TEMP);
	CheckAck();
	StopI2C()
	StartI2C();
	WriteByte((address << 1) | READ);
	CheckAck();
	data[0] = ReadByte();
	SendAck();
	data[1] = ReadByte();
	SendAck();
	data[2] = ReadByte();
	SendAck();
	data[3] = ReadByte();
	SendNack();
	StopI2C();

temp = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];
My question is, how do I convert this into picaxe basic? Here is my attempt...


Code:
setfreq k500				'running very slowly - not sure if this is necessary

for b6 = $07 to $77   			'scan all possible i2c addresses
b6 = b6*2					'shift left to vacate lsb (reserved for read/write flag)
i2cslave b6,i2cslow,i2cbyte		'configure i2c
writei2c b6,($21)			'send a byte to request sending of 4 temperature bytes
pause 20		
readi2c b6,(b0,b1,b2,b3)		'read the 4 temperature bytes

b6 =b6/2					'restore original value of b6 
sertxd (#b6," returns: ",#b0,#b1,#b2,#b3,13,10)		'display the interogated bytes
next b6
end

This goes through all the possible (7 bit) addresses, but none of them respond. Although the datasheet says the default address is $23.

The sertxd output shows that the bytes finish with the value of 255. As they start at 0, I suspect that this is because the SDA line is just pulled high all the time. Suggests that I am reading the bus, but not communicating with the slave device.

Any ideas?

So here are some more precisely formulated questions...

  • Can the Picaxe 'ping' an i2c slave easily? How would I do that?
  • The documentation says that the code for GET_TEMP is 0x21. Does that mean I need to send a word? I tried this but it makes no difference.
  • Likewise the address is 0x23 - do I need to address it with a word? [address is %0100011 + lsb=read/write bit, so I shift left one place = %01000110]
  • Does the writei2c command send a byte with the slave address? The documentation says to do this, but I have tried it with

Code:
writei2c $46($46,$21)
and
Code:
writei2c $46($21)
and both do the same thing (nothing useful)

  • I am still not sure about the clock speed. how does the i2cslow relate to clock speed. Some other users of this chip say that it can't quite handle 100MHz, but works OK at 80 or 90. How can I get the bus to go at 80MHz with a Picaxe 40x2?

Thanks for any help...

Mike
 

neiltechspec

Senior Member
Without seeing the datasheet, can't be sure.

But from the info you have given, maybe something like this would work.

hi2csetup i2cmaster,$23,i2cslow,i2cbyte
hi2cin $21,(b0,b1,b2,b3)
sertxd (#b0,#b1,#b2,#b3)

Neil.
 

Technical

Technical Support
Staff member
We would expect it to be

hi2csetup i2cmaster,$46,i2cslow,i2cbyte
hi2cin $21,(b0,b1,b2,b3)
sertxd (#b0,#b1,#b2,#b3)
 

Technical

Technical Support
Staff member
The code we have posted exactly matches the C code example. So if it is not working we suspect an electrical wiring issue.
However you could try this if the third party board does not correctly support the i2c restart:

hi2csetup i2cmaster,$46,i2cslow,i2cbyte
hi2cout ($21)
hi2cin (b0,b1,b2,b3)
sertxd (#b0,#b1,#b2,#b3)
 
Top