microwire_master.c File Reference

library to communicate using microwore as master (code) More...

Go to the source code of this file.

## Macros

#define | MICROWIRE_MASTER_SDO_PORT A
| SDO output signal port (to be connected on D slave signal)
#define | MICROWIRE_MASTER_SDO_PIN 0
| SDO output signal pin (to be connected on D slave signal)
#define | MICROWIRE_MASTER_SDI_PORT A
| SDO input signal port (to be connected on Q slave signal)
#define | MICROWIRE_MASTER_SDI_PIN 2
| SDO input signal pin (to be connected on Q slave signal)
#define | MICROWIRE_MASTER_SCK_PORT A
| SCK output signal port (to be connected on C slave signal)
#define | MICROWIRE_MASTER_SCK_PIN 4
| SCK output signal pin (to be connected on C slave signal)
#define | MICROWIRE_MASTER_TIMER 4
| timer peripheral

## Functions

void | microwire_master_setup (uint32_t frequency, bool organization_x16, uint8_t address_size)
| setup microwire peripheral More...
static void | microwire_master_wait_clock (void)
| wait for clock tick used to synchronise communication
static void | microwire_master_send_bit (bool bit)
| send bit over microwire More...
static void | microwire_master_start (uint8_t operation, uint32_t address)
| initialize microwire communication and send header (with leading start bit '1') More...
static void | microwire_master_stop (void)
| stop microwire communication and end all activities
static bool | microwire_master_read_bit (void)
| read bit from microwire communication More...
void | microwire_master_read (uint32_t address, uint16_t *data, size_t length)
| read data from slave memory More...
void | microwire_master_write_enable (void)
| enable write and erase operations More...
void | microwire_master_write_disable (void)
| disable write and erase operations More...
void | microwire_master_write (uint32_t address, uint16_t data)
| write data to slave memory More...
void | microwire_master_wait_ready (void)
| wait until slave is ready after a write or erase
void | microwire_master_erase (uint32_t address)
| erase memory More...
void | microwire_master_erase_all (void)
| erase all memory More...
void | microwire_master_write_all (uint16_t data)
| write data to all slave memory More...

## Variables

uint8_t | mirowire_master_address_size = 0
| address size used in operations (slave specific)
bool | mirowire_master_organization_x16 = true
| organization used (true=x16, false=x8)

## Detailed Description

library to communicate using microwore as master (code)

Author
  King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info

Date
  2017

Note
  peripherals used: GPIO GPIO peripheral used to communicate, timer timer peripheral used to generate timing for the signal microwire is a 3-Wire half-duplex synchronous bus. It is very similar to SPI without fixed length messages (bit-wised).
  the user has to handle the slave select pin (high during operations) so to be able to handle multiple slaves.

Warning
  this library implements the M93Cx8 EEPROM operation codes. Other microwire-based ICs might use different ones.

Definition in file microwire_master.c.

## Function Documentation

## microwire_master_erase()

void microwire_master_erase | ( | uint32_t | address | ) |

erase memory

Parameters

  [in] | address | memory address of data to read

Note
  after each erase and before the next operation user should wait for the slave to be ready

Definition at line 275 of file microwire_master.c.

## microwire_master_erase_all()

void microwire_master_erase_all | ( | void |  | ) |

erase all memory

Note
  after each erase and before the next operation user should wait for the slave to be ready

Definition at line 286 of file microwire_master.c.

## microwire_master_read()

void microwire_master_read | ( | uint32_t | address,
|  | uint16_t * | data,
|  | size_t | length
| ) |  |

read data from slave memory

Parameters

  [in] | address | memory address of data to read
  [out] | data | array to store read data
  [in] | length | number of data bytes/words to read

Definition at line 186 of file microwire_master.c.

## microwire_master_read_bit()

static bool microwire_master_read_bit | ( | void |  | ) |

static

read bit from microwire communication

Returns
  bit value (true = '1', false = '0')

Definition at line 177 of file microwire_master.c.

## microwire_master_send_bit()

static void microwire_master_send_bit | ( | bool | bit | ) |

static

send bit over microwire

Parameters

  [in] | bit | bit to send (true = '1', false = '0')

Definition at line 106 of file microwire_master.c.

## microwire_master_setup()

void microwire_master_setup | ( | uint32_t | frequency,
|  | bool | organization_x16,
|  | uint8_t | address_size
| ) |  |

setup microwire peripheral

Parameters

  [in] | frequency | clock frequency in Hz
  [in] | organization_x16 | if x16 memory organization (16-bits) is used, or x8 (8-bits)
  [in] | address_size | address size in bits

Note
  frequency practically limited to 500 kHz due to the software implementation nature

Definition at line 60 of file microwire_master.c.

## microwire_master_start()

static void microwire_master_start | ( | uint8_t | operation,
|  | uint32_t | address
| ) |  |

static

initialize microwire communication and send header (with leading start bit '1')

Parameters

  [in] | operation | operation code to send (2 bits)
  [in] | address | slave memory address to select

Definition at line 123 of file microwire_master.c.

## microwire_master_write()

void microwire_master_write | ( | uint32_t | address,
|  | uint16_t | data
| ) |  |

write data to slave memory

Parameters

  [in] | address | memory address of data to read
  [in] | data | byte/word to write

Note
  after each write and before the next operation user should wait for the slave to be ready

Definition at line 237 of file microwire_master.c.

## microwire_master_write_all()

void microwire_master_write_all | ( | uint16_t | data | ) |

write data to all slave memory

Parameters

  [in] | data | byte/word to write

Note
  after each write and before the next operation user should wait for the slave to be ready

Definition at line 297 of file microwire_master.c.

## microwire_master_write_disable()

void microwire_master_write_disable | ( | void |  | ) |

disable write and erase operations

Note
  this should be done after every complete write operation to protect against corruption

Definition at line 226 of file microwire_master.c.

## microwire_master_write_enable()

void microwire_master_write_enable | ( | void |  | ) |

enable write and erase operations

Note
  on slave boot write is disable to prevent corruption

Definition at line 215 of file microwire_master.c.