Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: M24SR.cpp
- Revision:
- 1:e356ce0033e4
- Parent:
- 0:37cdeb4f5b6c
- Child:
- 2:de5aea7f83cd
--- a/M24SR.cpp Mon Jul 15 14:44:13 2019 +0100 +++ b/M24SR.cpp Fri Jul 19 16:08:18 2019 +0100 @@ -91,7 +91,7 @@ #define GETLSB(val) ((uint8_t) (val & 0x00FF)) #define SWAPS(val) (uint16_t) ((val & 0x00FF) << 8) | ((val & 0xFF00) >> 8); -/** Default I2C Frequency 500 kHz */ +/** Default I2C Frequency 500 kHz (820 kHz maximum) */ #define M24SR_DEFAULT_FREQUENCY (uint32_t)500000 @@ -110,7 +110,7 @@ void M24SR::frequency(uint32_t hz) { - _i2c.frequency(hz); + _i2c.frequency(hz); } @@ -208,11 +208,45 @@ return M24SR_WRONG_LENGHT; } +#if (M24SR_READ_CONTINOUS) + + int16_t wlen = 0; // read length + int16_t dlen = size; // data length remaining + int16_t addr_ofst = 0; // address to read + + while (dlen > 0) + { + wlen = ((dlen > MAX_PAYLOAD ) ? MAX_PAYLOAD : dlen); + + // if addr is not at the start of a page then read bytes until we hit the boundary + if ( addr_ofst == 0 && (addr % MAX_PAYLOAD ) != 0 ) + { + wlen = MAX_PAYLOAD - (addr % MAX_PAYLOAD ); + // check we have enough data + if (size < wlen) + { + wlen = size; + } + } + + //printf("Read: Addr:%d Write: %d Remain: %d next: %d\n", addr + addr_ofst, wlen, dlen - wlen , addr_ofst + wlen); + + // read in blocks of %MAX_PAYLOAD% + if ( (ret = read_binary( _ndef_hdr_size + addr + addr_ofst, wlen, (uint8_t*)data + addr_ofst )) != M24SR_SUCCESS ) + { + return ret; + } + + + dlen -= wlen; + addr_ofst += wlen; + } +#else if ( (ret = read_binary( _ndef_hdr_size + addr, size, (uint8_t*)data )) != M24SR_SUCCESS ) { return ret; } - +#endif return M24SR_SUCCESS; } @@ -240,6 +274,7 @@ return M24SR_WRONG_LENGHT; } +#if (M24SR_WRITE_CONTINOUS) int16_t wlen = 0; // write length int16_t dlen = size; // data length remaining @@ -272,6 +307,13 @@ dlen -= wlen; addr_ofst += wlen; } +#else + // printf("Write:%d\r\n", size); + if ( (ret = update_binary( _ndef_hdr_size + addr , size, (uint8_t*)data )) != M24SR_SUCCESS ) + { + return ret; + } +#endif // #if (M24SR_WRITE_CONTINOUS) return M24SR_SUCCESS; } @@ -759,7 +801,7 @@ M24SR::status_t M24SR::io_poll_i2c() { /* Make sure we don't block forever */ - int16_t ctr = 2255; + int8_t ctr = 100; int status = 1; while ( status != 0 && ctr != 0 )