Skip to content
Snippets Groups Projects
Commit 722ca9de authored by Matthew Boeding's avatar Matthew Boeding
Browse files

I2C working correctly. Both devices are detected

parent bce508db
No related branches found
No related tags found
1 merge request!1Working LCD bitmaps.
...@@ -11,20 +11,20 @@ ...@@ -11,20 +11,20 @@
"targetId": "py32f030x8", "targetId": "py32f030x8",
"svdFile": "CMSIS/Device/PY32F0xx/py32f030axx.svd", "svdFile": "CMSIS/Device/PY32F0xx/py32f030axx.svd",
"preLaunchTask": "Build", "preLaunchTask": "Build",
"showDevDebugOutput":"none", "showDevDebugOutput":"raw",
}, },
{ {
"name": "J-Link", "name": "J-Link",
"type": "cortex-debug", "type": "cortex-debug",
"request": "launch", "request": "launch",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"executable": "build/${workspaceFolderBasename}.elf", "executable": "${workspaceRoot}\\build\\${workspaceFolderBasename}.elf",
"servertype": "jlink", "servertype": "jlink",
//"armToolchainPath": "C:\\Users\\developer\\Documents\\MBoeding\\Development\\13.2-Rel1\\bin",
"device": "py32f030x8", "device": "py32f030x8",
//"device": "Cortex-M0",
"svdFile": "CMSIS/Device/PY32F0xx/py32f030axx.svd", "svdFile": "CMSIS/Device/PY32F0xx/py32f030axx.svd",
"preLaunchTask": "Build", "preLaunchTask": "Build",
"showDevDebugOutput":"none", "showDevDebugOutput":"raw",
} }
] ]
} }
\ No newline at end of file
...@@ -146,7 +146,7 @@ AS_INCLUDES = ...@@ -146,7 +146,7 @@ AS_INCLUDES =
# compile gcc flags # compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -Wno-maybe-uninitialized -fdata-sections -ffunction-sections CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -Wno-maybe-uninitialized -fdata-sections -ffunction-sections -v
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2 CFLAGS += -g -gdwarf-2
......
#include <stdio.h> #include <stdio.h>
#include "py32f0xx.h" #include <py32f0xx.h>
#include <py32f030x8.h> #include <py32f030x8.h>
#include <py32f0xx_hal_gpio.h> #include <py32f0xx_hal_gpio.h>
#include "py32f0xx_hal_i2c.h" #include <py32f0xx_hal_i2c.h>
#include <py32f0xx_hal_gpio_ex.h> #include <py32f0xx_hal_gpio_ex.h>
#include "py32f0xx_hal.h" #include <py32f0xx_hal.h>
#define DUMMY_REGISTER 0x00 #define DUMMY_REGISTER 0x00
#define I2C_SPEEDCLOCK 100000 /* Communication speed 100K */ #define I2C_SPEEDCLOCK 100000 /* Communication speed 100K */
...@@ -19,21 +19,24 @@ void SysTick_Handler() ...@@ -19,21 +19,24 @@ void SysTick_Handler()
} }
void GPIO_I2C_Init(void) { void GPIO_I2C_Init(void) {
__HAL_RCC_I2C_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_I2C_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
// Configure SCL (Pin 6) // Configure SCL (Pin 6)
GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; // Open Drain for I2C GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; // Open Drain for I2C
//GPIO_InitStruct.Pull = GPIO_PULLUP; // Pull-up resistor GPIO_InitStruct.Pull = GPIO_PULLUP; // Pull-up resistor
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; // High speed GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; // High speed
GPIO_InitStruct.Alternate = GPIO_AF6_I2C;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
__HAL_RCC_I2C_FORCE_RESET();
__HAL_RCC_I2C_RELEASE_RESET();
// Configure SDA (Pin 7) // Configure SDA (Pin 7)
GPIO_InitStruct.Pin = GPIO_PIN_7; //GPIO_InitStruct.Pin = GPIO_PIN_7;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); //HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
} }
void I2C_Init(void) { void I2C_Init(void) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment