Commit f88d705d authored by Martin Horauer's avatar Martin Horauer
Browse files

added I2C example

parent b30aa796
/* mbed Example Program
* Copyright (c) 2006-2014 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/******************************************************************* Includes */
#include "mbed.h"
#include "ADJDs311.h"
/******************************************************************** Globals */
ADJDs311 colorSensor(P5_0, P5_2, P1_14); // SDA, SCL, LED
Serial pc(P0_1, P0_0); // tx, rx
/****************************************************************** Functions */
/**
* Main Function
*/
int main() {
RGBC color, cap, inte, offset;
/* Turn on the board LED */
colorSensor.ledMode(true);
/* Calibrate sensor */
pc.printf("Calibration started.\n\rPress any key to continue...\n\r");
while(!pc.readable());
colorSensor.calibrate();
/* Discard any received chars */
while(pc.readable())
{
pc.getc();
}
/* Get and set sensor offset */
pc.printf("Getting offset\n\rPress any key to continue...\n\r");
while(!pc.readable());
offset = colorSensor.setOffset();
/* Discard any received chars */
while(pc.readable())
{
pc.getc();
}
/* Get the gain of the capacitors and the integration time slot */
cap = colorSensor.getColorCap();
inte = colorSensor.getColorInt();
/* Print calibration data */
pc.printf("\n\n\n\rCalibration completed.\n\r");
pc.printf("\nCaps:\t\tr: %4d,\tg: %4d,\tb: %4d,\tc: %4d\n\r", cap.red, cap.green, cap.blue, cap.clear);
pc.printf("Ints:\t\tr: %4d,\tg: %4d,\tb: %4d,\tc: %4d\n\r", inte.red, inte.green, inte.blue, inte.clear);
pc.printf("Offsets:\tr: %4d,\tg: %4d,\tb: %4d,\tc: %4d\n\r", offset.red, offset.green, offset.blue, offset.clear);
/* Press key to continue with color measurement */
pc.printf("\nPress any key to continue\n\r");
while(!pc.readable());
while(pc.readable())
{
pc.getc();
}
/* Turn on the Led and print continuously the color data */
colorSensor.ledMode(true);
while(1) {
/* Get color data from the senosr */
color = colorSensor.read();
pc.printf("red: %4d,\tgreen: %4d,\tblue: %4d,\tclear: %4d\r", color.red, color.green, color.blue, color.clear);
wait(0.15);
}
}
/*EOF*/
../mbed-os/
\ No newline at end of file
https://github.com/mbed-Infineon-XMC/mbed-os.git
"""
mbed SDK
Copyright (c) 2016 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import subprocess
from os.path import join, abspath, dirname
#ROOT = abspath(join(dirname(__file__), "."))
##############################################################################
# Build System Settings
##############################################################################
#BUILD_DIR = abspath(join(ROOT, "build"))
# ARM
#ARM_PATH = "C:/Program Files/ARM"
# GCC ARM
#GCC_ARM_PATH = ""
GCC_ARM_PATH = dirname(subprocess.check_output(["which", "arm-none-eabi-gcc"]))
# GCC CodeRed
#GCC_CR_PATH = "C:/code_red/RedSuite_4.2.0_349/redsuite/Tools/bin"
# IAR
#IAR_PATH = "C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.0/arm"
# Goanna static analyser. Please overload it in private_settings.py
#GOANNA_PATH = "c:/Program Files (x86)/RedLizards/Goanna Central 3.2.3/bin"
#BUILD_OPTIONS = []
# mbed.org username
#MBED_ORG_USER = ""
# About
= About
The following guide describes the steps to build and run the mbed applications
targeting the XMC 4500 Relax Kit board from Infineon.
......@@ -15,23 +15,39 @@ Checkout the comments in the main.cpp files of every application - these
examples are heavily commented and refer to the respective files where the
classes, methods and definitions are found.
## Import the project
== Import the project
```
[source%nowrap, bash]
----
$ git clone https://es.technikum-wien.at/bel/bel4_ezb_public.git
$ cd XMC_MBED/
```
----
# Step-by-Step Building/Flashing/Debugging
== Import a library
## Compile a project
Libraries can be added to the project using `mbed add LINK` where LINK points
to the respective repository, e.g.:
----
mbed add https://mbed.org/users/CheeseW/code/ADJDs311/#5d0bc4df0701
----
This adds a folder `ADJDs311` containing the respective sources and adds a file
`ADJDs311.lib` that simply contains the above link. This löibrary will than be
considered when the project is being built.
= Step-by-Step Building/Flashing/Debugging
== Compile a project
Navigate into the project folder and build it using:
```
[source%nowrap, bash]
----
cd APP_BB_BLINKY/
mbed compile -m XMC_4500_RELAX_KIT -t GCC_ARM -N main
```
----
mbed creates a BUILD directory where you can find the executable (`*.bin`, `*.elf`, `*.hex` ...).
[NOTE]
......@@ -42,41 +58,46 @@ replace it with a Windows symbolic link using `mklink /D mbed-os ..\mbed-os`.
Use the JLink tools to flash the application hexfile to the Relax-Kit.
```
[source%nowrap, bash]
----
$ JLinkExe -device XMC4500-1024 -if SWD -speed 4000 -autoconnect 1
J-LINK> h
J-Link> loadfile BUILD/XMC_4500_RELAX_KIT/GCC_ARM/main.hex
J-Link> r
J-Link> g
```
----
## Debugging
== Debugging
To the debug the application 4 steps in sequence are necessary.
(1) You will need to create the executable with DEBUg symbols. To that end add
`--profile mbed-os/tools/profiles/debug.json` to the build command.
```
[source%nowrap, bash]
----
mbed compile -m XMC_4500_RELAX_KIT -t GCC_ARM -N main --profile mbed-os/tools/profiles/debug.json
```
----
(2) Start the `JLinkGDEBServer`, e.g.:
```
[source%nowrap, bash]
----
JLinkGDBServer -Device XMC4500-1024 -if SWD
```
----
(3) In order to log messages printed to `stdout` we connect to port 2333 via
telnet.
```
[source%nowrap, bash]
----
telnet 127.0.0.1 2333
```
----
(4) We launch the debugger and control the debug session:
```
[source%nowrap, bash]
----
arm-none-eabi-gdb -q BUILD/XMC_4500_RELAX_KIT/GCC_ARM/main.elf
(gdb) target remote :2331
(gdb) monitor reset
......@@ -85,14 +106,15 @@ arm-none-eabi-gdb -q BUILD/XMC_4500_RELAX_KIT/GCC_ARM/main.elf
(gdb) b main
(gdb) c
[...]
```
----
# Makefile Building/Flashing/Debugging
= Makefile Building/Flashing/Debugging
Using the prepared `Makefile` one can invoke trhe following actions in a more
convenient way:
```
[source%nowrap, bash]
----
make # build the application with debug symbols
make debug # -"-
make release # debug a release version of the project
......@@ -101,7 +123,7 @@ make debug # debug the application
make erase # erase the program memory
make doc # invoke doxygen
make clean # clean the project
```
----
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment