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.
main.cpp
- Committer:
- rutles
- Date:
- 2014-06-12
- Revision:
- 1:20b452641613
- Parent:
- 0:1913ea9baf30
File content as of revision 1:20b452641613:
// fc1114 - Frequency counter with i2c slave.
// target: LPC1114FN28
#include "mbed.h"
#define I2C_ADRS 0x70
DigitalOut led(dp28);
I2CSlave slave(dp5, dp27);
Ticker tick;
volatile uint32_t frq;
void isr_tick(){
frq = LPC_TMR32B0->TC;
LPC_TMR32B0->TC = 0;
led = !led;
}
int main() {
union {
char b[4];
uint32_t w;
} buf;
char dummy[4];
led = 1;
tick.attach(&isr_tick, 1);
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 9);//TMR32B0 wakeup
LPC_IOCON->PIO1_5 |= (1 << 1);// Set PIN14 as CT32B0_CAP0
LPC_IOCON->PIO1_5 |= (1 << 5);// Hysteresis enable
LPC_TMR32B0->TCR = 2; // reset
LPC_TMR32B0->CTCR = 1; // counter mode
LPC_TMR32B0->CCR = 0; // Input Capture Disable)
LPC_TMR32B0->PR = 0;// no prescale
LPC_TMR32B0->TCR = 1; // start
slave.address(I2C_ADRS << 1);
while (1) {
int i = slave.receive();
switch (i) {
case I2CSlave::ReadAddressed:
buf.w = frq;
slave.write(buf.b, 4);
break;
case I2CSlave::WriteGeneral:
slave.read(dummy, 4);
break;
case I2CSlave::WriteAddressed:
slave.read(dummy, 4);
break;
}
}
}