Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
06cf2379
Commit
06cf2379
authored
May 03, 2019
by
schneider
Browse files
feat(i2c): scan bus in hello world
parent
12316fe3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Hello_World/Makefile
View file @
06cf2379
...
...
@@ -90,6 +90,8 @@ PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
#PROJ_CFLAGS+=--specs=nano.specs
#PROJ_LDFLAGS+=--specs=nano.specs
PROJ_CFLAGS
+=
-std
=
c99
# Point this variable to a startup file to override the default file
#STARTUPFILE=start.S
...
...
Hello_World/main.c
View file @
06cf2379
...
...
@@ -47,13 +47,22 @@
#include
"led.h"
#include
"board.h"
#include
"tmr_utils.h"
#include
"i2c.h"
/***** Definitions *****/
#define I2C_DEVICE MXC_I2C0_BUS0
/***** Globals *****/
/***** Functions *****/
#if 0
void I2C0_IRQHandler(void)
{
I2C_Handler(I2C_DEVICE);
return;
}
#endif
// *****************************************************************************
int
main
(
void
)
{
...
...
@@ -61,6 +70,23 @@ int main(void)
printf
(
"Hello World!
\n
"
);
//Setup the I2CM
I2C_Shutdown
(
I2C_DEVICE
);
I2C_Init
(
I2C_DEVICE
,
I2C_FAST_MODE
,
NULL
);
#if 0
NVIC_EnableIRQ(I2C0_IRQn); // Not sure if we actually need this when not doing async requests
#endif
uint8_t
dummy
[
1
]
=
{
0
};
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for
(
int
addr
=
0x8
;
addr
<
0x78
;
++
addr
)
{
// A 0 byte write does not seem to work so always send a single byte.
int
res
=
I2C_MasterWrite
(
I2C_DEVICE
,
addr
<<
1
,
dummy
,
1
,
0
);
if
(
res
==
1
)
{
printf
(
"Found (7 bit) address 0x%02x
\n
"
,
addr
);
}
}
while
(
1
)
{
LED_On
(
0
);
TMR_Delay
(
MXC_TMR0
,
MSEC
(
500
),
0
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment