--- /dev/null
+/**
+ ********************************************************
+ *
+ * Converter Board specific functions
+ *
+ ********************************************************
+ */
+
+#include "CB_functions.h"
+
+#include "periph_conf.h"
+
+
+
+void decode_register(uint8_t addr,uint16_t *registers) {
+ uint16_t thisRegister = registers[addr];
+ switch (addr){
+ case 0x0:
+// thisRegister[thisRegister]++; // just for debug reasons
+ USART_SendData(USART1, addr);
+ while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
+ USART_SendData(USART1, (uint8_t) (thisRegister>>8)); // upper nibble
+ while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
+ USART_SendData(USART1, (uint8_t) (thisRegister & 0x00FF)); // lower nibble
+ while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
+
+ break;
+ case 0x1: // Switches0
+ CB_GPIO_Out(ENAA0,thisRegister & 1<<5);
+ CB_GPIO_Out(DISA0,thisRegister & 1<<4);
+ CB_GPIO_Out(ENAD0,thisRegister & 1<<3);
+ CB_GPIO_Out(DISD0,thisRegister & 1<<2);
+ CB_GPIO_Out(SENSOREN0,thisRegister & 1<<1);
+ CB_GPIO_Out(JTAGEN0,thisRegister & 1<<0);
+ break;
+ case 0x2: // Switches1
+ CB_GPIO_Out(ENAA1,thisRegister & 1<<5);
+ CB_GPIO_Out(DISA1,thisRegister & 1<<4);
+ CB_GPIO_Out(ENAD1,thisRegister & 1<<3);
+ CB_GPIO_Out(DISD1,thisRegister & 1<<2);
+ CB_GPIO_Out(SENSOREN1,thisRegister & 1<<1);
+ CB_GPIO_Out(JTAGEN1,thisRegister & 1<<0);
+ break;
+
+ case 0x10: // LEDs
+ if(thisRegister & 1<<7) {
+ CB_GPIO_Out(LED4,thisRegister & 1<<3);
+ }
+ if(thisRegister & 1<<6) {
+ CB_GPIO_Out(LED3,thisRegister & 1<<2);
+ }
+ if(thisRegister & 1<<5) {
+ CB_GPIO_Out(LED2,thisRegister & 1<<1);
+ }
+ if(thisRegister & 1<<4) {
+ CB_GPIO_Out(LED1,thisRegister & 1<<0);
+ }
+ break;
+
+
+ }
+
+
+}
+
+
+void init_CB_GPIO_Outputs(void) {
+
+ CB_GPIO_Out_Init(LED1);
+ CB_GPIO_Out_Init(LED2);
+ CB_GPIO_Out_Init(LED3);
+ CB_GPIO_Out_Init(LED4);
+ CB_GPIO_Out_Init(JTAGEN0);
+ CB_GPIO_Out_Init(JTAGEN1);
+ CB_GPIO_Out_Init(SENSOREN0);
+ CB_GPIO_Out_Init(SENSOREN1);
+ CB_GPIO_Out_Init(DISD0);
+ CB_GPIO_Out_Init(DISA0);
+ CB_GPIO_Out_Init(DISD1);
+ CB_GPIO_Out_Init(DISA1);
+ CB_GPIO_Out_Init(ENAD0);
+ CB_GPIO_Out_Init(ENAA0);
+ CB_GPIO_Out_Init(ENAD1);
+ CB_GPIO_Out_Init(ENAA1);
+// CB_GPIO_Out_Init(OVCD_C0); //input!
+// CB_GPIO_Out_Init(OVCA_C0); //input!
+// CB_GPIO_Out_Init(OVCD_C1); //input!
+// CB_GPIO_Out_Init(OVCA_C1); //input!
+ CB_GPIO_Out_Init(MUXADDR0);
+ CB_GPIO_Out_Init(MUXADDR1);
+ CB_GPIO_Out_Init(ZEROCALIB);
+ CB_GPIO_Out_Init(ADC_CONV0);
+ CB_GPIO_Out_Init(ADC_CONV1);
+ CB_GPIO_Out_Init(DAC_CS);
+ CB_GPIO_Out_Init(UC_CS);
+
+
+ CB_GPIO_Out_Hi(LED1);
+ CB_GPIO_Out_Lo(LED2);
+ CB_GPIO_Out_Lo(LED3);
+ CB_GPIO_Out_Lo(LED4);
+ CB_GPIO_Out_Hi(JTAGEN0);
+ CB_GPIO_Out_Hi(JTAGEN1);
+ CB_GPIO_Out_Hi(SENSOREN0);
+ CB_GPIO_Out_Hi(SENSOREN1);
+ CB_GPIO_Out_Lo(DISD0);
+ CB_GPIO_Out_Lo(DISA0);
+ CB_GPIO_Out_Lo(DISD1);
+ CB_GPIO_Out_Lo(DISA1);
+ CB_GPIO_Out_Hi(ENAD0);
+ CB_GPIO_Out_Hi(ENAA0);
+ CB_GPIO_Out_Hi(ENAD1);
+ CB_GPIO_Out_Hi(ENAA1);
+// CB_GPIO_Out_Lo(OVCD_C0); //input!
+// CB_GPIO_Out_Lo(OVCA_C0); //input!
+// CB_GPIO_Out_Lo(OVCD_C1); //input!
+// CB_GPIO_Out_Lo(OVCA_C1); //input!
+ CB_GPIO_Out_Lo(MUXADDR0);
+ CB_GPIO_Out_Lo(MUXADDR1);
+ CB_GPIO_Out_Lo(ZEROCALIB);
+ CB_GPIO_Out_Hi(ADC_CONV0); // spi nCS -> idle Hi
+ CB_GPIO_Out_Hi(ADC_CONV1); // spi nCS -> idle Hi
+ CB_GPIO_Out_Hi(DAC_CS); // spi nCS -> idle Hi
+ CB_GPIO_Out_Hi(UC_CS); // spi nCS -> idle Hi
+
+}
\ No newline at end of file
--- /dev/null
+/**
+ ********************************************************
+ *
+ * Converter Board specific functions (headers)
+ *
+ ********************************************************
+ */
+
+#include "stm32f10x.h"
+#include "stm32f10x_conf.h" // contains all std periph includes
+#include "core_cm3.h"
+// #include "stm32f10x_it.h"
+
+
+void init_CB_GPIO_Outputs(void);
+void decode_register(uint8_t addr,uint16_t *registers);
\ No newline at end of file
OBJS+=stm32f10x_it.o
OBJS+=periph_conf.o
OBJS+=CB_functions.o
+OBJS+=usart1.o
# OBJS+=keypins.o
#include <stdio.h>
#include "newlib_stubs.c"
#include "CB_functions.h"
+#include "usart1.h"
#define UC_NO_REGS 17
/* function prototypes */
-void RCC_Configuration(void);
-void GPIO_Configuration(void);
-void NVIC_Configuration(void);
+
void USART1_IRQHandler(void);
-void init_USART1_w_interrupt(void);
SPIBuffer[0] = 0x1234;
SPIBuffer[1] = 0x5678;
- init_USART1_w_interrupt();
+ init_USART1();
-void init_USART1_w_interrupt(void) {
- /* structure contains data for USART configuration */
- USART_InitTypeDef USART_InitStructure;
-
- /* HW configuration */
- RCC_Configuration();
- GPIO_Configuration();
- NVIC_Configuration();
-
- /* USARTx configuration ---------------------------------------------------*/
- USART_InitStructure.USART_BaudRate = 9600;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No ;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
-
- /* Configurating and enabling USART1 */
- USART_Init(USART1, &USART_InitStructure);
- USART_Cmd(USART1, ENABLE);
-
- /* Enabling interrupt from USART1 */
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
-
- while (1);
-}
-
-/* clock sources configuration */
-void RCC_Configuration(void)
-{
- /* error status */
- ErrorStatus HSEStartUpStatus;
-
- RCC_DeInit();
-
- RCC_HSEConfig(RCC_HSE_ON);
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
-
- if (HSEStartUpStatus == SUCCESS) {
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
- FLASH_SetLatency(FLASH_Latency_2);
-
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
- RCC_PCLK2Config(RCC_HCLK_Div1);
- RCC_PCLK1Config(RCC_HCLK_Div2);
-
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- RCC_PLLCmd(ENABLE);
- while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
-
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
- while (RCC_GetSYSCLKSource() != 0x08);
- }
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
-}
-/* I/O ports configuration */
-void GPIO_Configuration(void)
-{
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Configuring USART1_Tx as 'alternate function push-pull' */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /* Configuring USART1_Rx as 'input floating' */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-}
-
-
-/* NVIC module configuration */
-void NVIC_Configuration(void)
-{
- NVIC_InitTypeDef NVIC_InitStructure;
-
- /* Place the vector table into FLASH */
- NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
-
- /* Enabling interrupt from USART1 */
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-}
--- /dev/null
+/**\r
+ ********************************************************\r
+ * \r
+ * USART1\r
+ * \r
+ ********************************************************\r
+ */\r
+\r
+#include "usart1.h"\r
+ \r
+void init_USART1(void) {\r
+ /* structure contains data for USART configuration */\r
+ USART_InitTypeDef USART_InitStructure;\r
+\r
+ /* HW configuration */\r
+ RCC_Configuration();\r
+ GPIO_Configuration();\r
+ NVIC_Configuration();\r
+ \r
+ /* USARTx configuration ---------------------------------------------------*/\r
+ USART_InitStructure.USART_BaudRate = 9600;\r
+ USART_InitStructure.USART_WordLength = USART_WordLength_8b;\r
+ USART_InitStructure.USART_StopBits = USART_StopBits_1;\r
+ USART_InitStructure.USART_Parity = USART_Parity_No ;\r
+ USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;\r
+ USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;\r
+ \r
+ /* Configurating and enabling USART1 */ \r
+ USART_Init(USART1, &USART_InitStructure);\r
+ USART_Cmd(USART1, ENABLE);\r
+\r
+ /* Enabling interrupt from USART1 */\r
+ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);\r
+\r
+ while (1);\r
+}\r
+\r
+\r
+/* clock sources configuration */\r
+void RCC_Configuration(void)\r
+{\r
+ /* error status */\r
+ ErrorStatus HSEStartUpStatus;\r
+ \r
+ RCC_DeInit();\r
+ \r
+ RCC_HSEConfig(RCC_HSE_ON);\r
+ HSEStartUpStatus = RCC_WaitForHSEStartUp();\r
+ \r
+ if (HSEStartUpStatus == SUCCESS) {\r
+ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);\r
+ FLASH_SetLatency(FLASH_Latency_2);\r
+ \r
+ RCC_HCLKConfig(RCC_SYSCLK_Div1); \r
+ RCC_PCLK2Config(RCC_HCLK_Div1); \r
+ RCC_PCLK1Config(RCC_HCLK_Div2);\r
+ \r
+ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);\r
+ RCC_PLLCmd(ENABLE);\r
+ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);\r
+ \r
+ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);\r
+ while (RCC_GetSYSCLKSource() != 0x08);\r
+ }\r
+ \r
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);\r
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);\r
+}\r
+\r
+\r
+/* I/O ports configuration */\r
+void GPIO_Configuration(void)\r
+{\r
+ GPIO_InitTypeDef GPIO_InitStructure;\r
+ \r
+ /* Configuring USART1_Tx as 'alternate function push-pull' */\r
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;\r
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;\r
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;\r
+ GPIO_Init(GPIOA, &GPIO_InitStructure);\r
+ \r
+ /* Configuring USART1_Rx as 'input floating' */\r
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;\r
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;\r
+ GPIO_Init(GPIOA, &GPIO_InitStructure);\r
+} \r
+\r
+\r
+/* NVIC module configuration */\r
+void NVIC_Configuration(void)\r
+{\r
+ NVIC_InitTypeDef NVIC_InitStructure;\r
+ \r
+ /* Place the vector table into FLASH */\r
+ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); \r
+ \r
+ /* Enabling interrupt from USART1 */\r
+ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;\r
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;\r
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;\r
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;\r
+ NVIC_Init(&NVIC_InitStructure);\r
+} \r
--- /dev/null
+/**\r
+ ********************************************************\r
+ * \r
+ * USART1 (headers)\r
+ * \r
+ ********************************************************\r
+ */\r
+ \r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "stm32f10x_conf.h"\r
+\r
+\r
+void init_USART1(void);\r
+void RCC_Configuration(void);\r
+void GPIO_Configuration(void);\r
+void NVIC_Configuration(void);
\ No newline at end of file