Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 08:46 28 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : 24AT32 eeprom Error: Invalid function

Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 06:32am 28 Feb 2017
Copy link to clipboard 
Print this post

I'm trying to use the 24AT32 eeprom library created by twofingers for the Maximite and modified by Centrex for the uMite MMBasic 4.5D (eeprom on DS3132 module). I am trying to run this on an Explore-64 board with MMBasic V3.5B.

Link here: http://www.thebackshed.com/forum/forum_posts.asp?TID=6917&KW=AT24C32

I can write without getting an error message (after removing "$" from "SUB eeWrite"), but get "Error: Invalid function" when trying to read with either the eeGet$ or eeRead$ functions.
[code]
[115] Function eeGet$ (address, amount)
Error: Invalid function definition
>
[/code]
[code]
[147] Function eeRead$ (address)
Error: Invalid function definition
>
[/code]
I've tried redefining them as "FUNCTION eeRead (address) AS STRING", but get the same message.

Here is stripped down code. What is wrong with the function definition?

[code]
'********************************************
'********************************************
' EEPROM-Library v0.81
' -----------------------------------------
' by twofingers 09-2014 at TBS
' with parts from MMBasic Library
' for AT24V32 (32kBit EEPROM)
' at DS3231 or DS1307 RTC-Modules etc.
' MMBasic 4.5 for Maximite/Duinomite

'Modified by Centrex to run on uMITE
'28 pin 150 MMBasic 4.5D (11-2014)
'The origonal here
' http://www.thebackshed.com/Forum/forum_posts.asp?TID=6917&PN =9
'------------------------------------------
' eeWrite$: writes a string to address
' eeRead$ : reads a string from address
' eeGet$ : returns an amount of bytes from address
' eeWriteB: writes 1 byte to address
' eeReadB : reads 1 byte from address
' address may be between 0 to 4095
'
' eeSaveF : writes a 32 bit floatinpoint number
' eeSaveF4: writes a 32 bit floatinpoint number
' at EEPROM addresses divisible by 4
' (faster then eeSaveF)
' eeLoadF : reads a 32 bit floatinpoint number
' back from EEPROM using PEEK and POKE
' needs eeWriteB and eeReadB
'
' eeErase : deletes the whole eeprom w. verify
' this has been remmed out for the time being
'
' eeDump : shows content of eeprom or parts
' eeMon : displays whole eeprom content (scroll)
' remmed out for the time being
'
' I2CPROM (I2C address of your EEPROM)
' must always be defined globally
'-------------------------------------------
'
' Remark: A check for defective Bytes
' has a latency of ~1 sec !!
' Therefore one second should be elapsed after
' each write event and then follow a read/compare,
' if a verify is required.
'
'-------------------------------------------
'
'
' This code may be freely distributed and
' changed. Provided AS IS without any warranty.
' Use it at your own risk.
'********************************************
'********************************************




'#######################################
' Demonstration code
'--------------------
I2CPROM = &H57 'I2CAdress of EEPROM
'if unknown please use the i2CSanner
'or then datasheet

Print "Writing at 0 'THE BACKSHED DEMO'"
eeWrite 0,"THE BACKSHED DEMO"

Print:Print "reading back:"

Print
Print eeGet$(0,17)
'Print eeRead$(0)


end ' end DEMO



'******************************
Sub eeWrite (address, text$)
' Writes a string to AT24C32
'******************************
Local a,x,msb,lsb,PByte

' I2CPROM=&H57 ' 24C32-DS3231
If I2CPROM = 0 Then Print "Error: Please define I2CPROM globally": End

a=0

If Len(text$)+address>4095 Then Print "Error: Address too high!":End

I2C open 100,100 'ENABLE I2C
For x= address To address+Len(text$) 'writes a 0-byte at the end!
a=a+1
msb=Int(x/256) 'MSB
lsb=x Mod 256 'LSB

PByte=0:If a<256 Then PByte=Asc(Mid$(text$,a,1))

I2C write I2CPROM, 0, 3, msb, lsb, PByte
If MM.I2C <>0 Then Print "Error! 1=NAK 2=TIMEOUT"; MM.I2C: End
Pause 1
Next x
I2C close
If debug Then
Print "The string "+Chr$(34);:Print text$;
Print Chr$(34)+" was successfully written at address"address" into EEPROM."
EndIf
End Sub


'******************************
Function eeGet$ (address, amount)
' Returning a amount of bytes from
' address of an AT24C32.
'******************************
Local x,msb,lsb,tmp

' I2CPROM=&H57 ' 24C32-DS3231
If I2CPROM = 0 Then Print "Error: Please define I2CPROM globally": End

eeGet$=""

If address>4095 Then Print "Error: Address too high!":End
If amount>255 Then Print "Error: String would be too long!":End

I2C open 100,100 'ENABLE I2C
For x= address To address+amount-1

msb=Int(x/256) 'MSB
lsb=x Mod 256 'LSB

I2C write I2CPROM, 0,2,msb,lsb
I2C read I2CPROM, 0,1,tmp

If MM.I2C <>0 Then Print "Error! 1=NAK 2=TIMEOUT"; MM.I2C: End
eeGet$=eeGet$+Chr$(tmp)

Next x
I2C close
End Function


'******************************
Function eeRead$ (address)
'eeRead$ (address):
' Reads a zero-terminated string from AT24C32
'******************************
Local msb,lsb,tmp
' I2CPROM=&H57 ' 24C32-DS3231
If I2CPROM = 0 Then Print "Error: Please define I2CPROM globally": End

eeRead$=""

If address>4094 Then Print "Error: Address too high! (valid: 0-4094)":End

I2C open 100,100 'ENABLE I2C

Do

msb=Int(address/256) 'MSB
lsb=address Mod 256 'LSB

I2C write I2CPROM, 0,2,msb,lsb
I2C read I2CPROM, 0,1,tmp

If MM.I2C <>0 Then Print "Error! 1=NAK 2=TIMEOUT"; MM.I2C: End
If tmp=0 Then Exit 'leave loop
eeRead$=eeRead$+Chr$(tmp)
address=address+1

Loop While Len(eeRead$)=<255

I2C close
Function end
'return


'***********************************************************
[/code]
LanceEdited by lizby 2017-03-01
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8582
Posted: 06:54am 28 Feb 2017
Copy link to clipboard 
Print this post

get rid of the space between the function name and the opening bracket
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 07:22am 28 Feb 2017
Copy link to clipboard 
Print this post

  matherp said   get rid of the space between the function name and the opening bracket


And presto! Both functions work. Thank you very much. I'll add a note to the original thread.

Lance

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 09:10am 28 Feb 2017
Copy link to clipboard 
Print this post

Hi Lizby!

Sorry for the trouble!!

I think you should use the updated version
2015-03-26_210818_eeProm_Lib_micromite_mk2_v0.82.zip
from 3/2015 in the original thread.

Regards
Michael
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 03:48pm 28 Feb 2017
Copy link to clipboard 
Print this post

Thanks for that.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024