Sorry, it's me again with another problem. I imagine you all must be getting tired of seeing posts started by me!
After successfully getting the FPU running on bread board and communication via serial cable to the IDE i moved on to the next step and fitted a 28x2 to the bread board and linked it to the FPU via I2C with a 4k7 resistor on each of the two connections.
I set the MCLR and CS pins high on the FPU to set it to I2C mode. All FPU settings are still on the factory defaults.
I downloaded the following program to the 28x2
Hopefully what i have pasted below will still work as i have had to delete a lot of the unused definitions so it was short enough to post. I'm hoping in my haste to post this i have not deleted something that is needed.
The code is basically the standard FPU template file but with the I2Cfast in the setup changed to I2Cslow_8. I have als added a few extra serial out commands to see what's going on.
What i see on the terminal is the following
(The É isn't what i'm seeing in the terminal! it's more of a 90 degree right pipe and in hex is 0xc9 i think after looking it up in an ascii list)
Sync_char 1 is what is meant to come back and sync_char 2 is what is actually coming back.
As you can see what's coming back isn't what is expected.
I have tried changing the I2C speed from fast to slow and no change. Also initially i was using I2CFast and not I2Cfast_8 but the result was still the same.
Clearly something isn't right with either my code or my wiring or both. Unfortunately i don't own a scope or even a logic probe. just a multimeter so i think debugging this is going to be a pain.
Can anyone see anything wrong with the code or suggest what else could be wrong?
Many thanks
Mike
After successfully getting the FPU running on bread board and communication via serial cable to the IDE i moved on to the next step and fitted a 28x2 to the bread board and linked it to the FPU via I2C with a 4k7 resistor on each of the two connections.
I set the MCLR and CS pins high on the FPU to set it to I2C mode. All FPU settings are still on the factory defaults.
I downloaded the following program to the 28x2
Hopefully what i have pasted below will still work as i have had to delete a lot of the unused definitions so it was short enough to post. I'm hoping in my haste to post this i have not deleted something that is needed.
Code:
'-------------------- uM-FPU V3.1 I2C definitions ------------------- 2011-10-17
symbol fpuID = 0xC8 ' uM-FPU I2C address
'-------------------- uM-FPU V3.1 opcode definitions ---------------------------
symbol SYNC = 0xF0 ' Get synchronization byte
symbol READSTATUS = 0xF1 ' Read status byte
symbol READSTR = 0xF2 ' Read string from string buffer
symbol VERSION = 0xF3 ' Copy version string to string buffer
symbol READVAR = 0xFC ' Read internal variable, store in reg[0]
symbol SYNC_CHAR = 0x5C ' sync character
'-------------------- uM-FPU variables -----------------------------------------
symbol dataByte = b13 ' data byte
symbol format = b13 ' format (same as dataByte)
symbol statusByte = b13 ' status byte (same as dataByte)
'==================== end of uM-FPU V3.1 I2C definitions =======================
'-------------------- main routine ---------------------------------------------
main:
pause 5000 ' wait for terminal window
sertxd (13, 10, 13, 10, "template", 13, 10)
sertxd (13, 10, 13, 10, "SYNC_CHAR 1 - ", SYNC_CHAR)
gosub fpu_reset ' reset the uM-FPU
sertxd (13, 10, 13, 10, "SYNC_CHAR 2 - ", statusByte)
if statusByte = SYNC_CHAR then
gosub print_version ' display the uM-FPU version number
else
sertxd (13, 10, "uM-FPU not detected.")
endif
' (insert application code here)
' hi2out, 0, (...)
done:
sertxd (13, 10, "Done.")
end ' end of program
'-------------------- uM-FPU V3.1 I2C support routines -------------- 2011-10-17
fpu_reset:
hi2csetup i2cmaster, fpuID, i2cslow_8, i2cbyte
sertxd (13, 10, "send reset")
hi2cout 1, (0) ' reset the uM-FPU
pause 10 ' wait for reset to complete
hi2cout 0, (SYNC) ' check for synchronization
goto fpu_readStatus2
fpu_wait:
hi2cin 0, (statusByte) ' wait for ready status
if statusByte <> 0 then fpu_wait
return
fpu_readStatus:
gosub fpu_wait ' read status byte
hi2cout 0, (READSTATUS)
fpu_readStatus2:
hi2cin 0, (statusByte) ' read status byte
return
print_version:
hi2cout 0, (VERSION) ' get the uM-FPU version string
goto print_fpuString ' print it
print_float:
format = 0 ' set for free format
' (fall through to print_floatFormat)
print_floatFormat:
hi2cout 0, (FTOA, format) ' convert floating point to formatted ASCII
goto print_fpuString ' print the string
print_long:
format = 0 ' set for free format
' (fall through to print_longFormat)
print_longFormat:
hi2cout 0, (LTOA, format) ' convert long integer to formatted ASCII
' (fall through to print_fpuString)
print_fpuString:
gosub fpu_wait ' wait until uM-FPU is ready
hi2cout 0, (READSTR)
print_string2:
hi2cin 0, (dataByte) ' display zero terminated string
if dataByte = 0 then Print_String3
if dataByte > 127 then Print_String3
sertxd(dataByte)
goto Print_String2
print_string3:
return ' end of string
'==================== end of uM-FPU V3.1 I2C support routines ==================
What i see on the terminal is the following
Code:
template
SYNC_CHAR 1 - \
SYNC_CHAR 2 - É
uM-FPU not detected.
Done.
Sync_char 1 is what is meant to come back and sync_char 2 is what is actually coming back.
As you can see what's coming back isn't what is expected.
I have tried changing the I2C speed from fast to slow and no change. Also initially i was using I2CFast and not I2Cfast_8 but the result was still the same.
Clearly something isn't right with either my code or my wiring or both. Unfortunately i don't own a scope or even a logic probe. just a multimeter so i think debugging this is going to be a pain.
Can anyone see anything wrong with the code or suggest what else could be wrong?
Many thanks
Mike