]> jspc29.x-matter.uni-frankfurt.de Git - mvd_firmware.git/commitdiff
added DAC control & its registers
authorJan Michel <j.michel@gsi.de>
Mon, 6 Jan 2014 17:56:39 +0000 (18:56 +0100)
committerJan Michel <j.michel@gsi.de>
Mon, 6 Jan 2014 17:56:39 +0000 (18:56 +0100)
firmware/src/CB_functions.c
firmware/src/Makefile
firmware/src/dac.c [new file with mode: 0644]
firmware/src/dac.h [new file with mode: 0644]
firmware/src/main.c
firmware/src/misc_utils.c
firmware/src/misc_utils.h

index 55958bd5be3b82eda5317cdefe57d1c080d9dc79..e563b3543cd68e7d119663dbbf8a4d2c55746341 100644 (file)
@@ -9,12 +9,25 @@
 #include "CB_functions.h"
 #include "periph_conf.h"
 #include "stm32f10x_conf.h"
+#include "misc_utils.h"
 
 
 
 uint16_t uC_regs[UC_NO_REGS];
 
-
+void uart_word_to_dac(uint16_t word){
+  while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
+  CB_GPIO_Out_Lo(DAC_CS);
+  
+  USART_SendData(USART3, reverse_8bit(0x30 | ((word>>12)&0xF)));
+  while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
+  USART_SendData(USART3, reverse_8bit((word>>4)&0xFF));
+  while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
+  USART_SendData(USART3, reverse_8bit((word<<4)&0xFF));
+  delay_ms(1);
+  while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
+  CB_GPIO_Out_Hi(DAC_CS);
+}
 
 void uart_byte_to_fpga(uint8_t byte){
   while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
@@ -61,6 +74,13 @@ void decode_register(uint8_t addr) {
       CB_GPIO_Out(SENSOREN0,thisRegister & 1<<1);
       CB_GPIO_Out(JTAGEN0,thisRegister & 1<<0);
       break;
+    case 0x2: //DAC CurLimA 0
+      uart_word_to_dac(((thisRegister&0xFFFF)>>4) | (0<<12));
+    case 0x3: //DAC CurLimD 0
+      uart_word_to_dac(((thisRegister&0xFFFF)>>4) | (1<<12));
+    case 0x4: //DAC VClp 0
+      uart_word_to_dac(((thisRegister&0xFFFF)>>4) | (2<<12));
+      
     case 0x6: // Switches1
       CB_GPIO_Out(ENAA1,thisRegister & 1<<5);
       CB_GPIO_Out(DISA1,thisRegister & 1<<4);
@@ -69,6 +89,16 @@ void decode_register(uint8_t addr) {
       CB_GPIO_Out(SENSOREN1,thisRegister & 1<<1);
       CB_GPIO_Out(JTAGEN1,thisRegister & 1<<0);
       break;
+    case 0x7: //DAC CurLimA 1
+      uart_word_to_dac(((thisRegister&0xFFFF)>>4) | (4<<12));
+    case 0x8: //DAC CurLimD 1
+      uart_word_to_dac(((thisRegister&0xFFFF)>>4) | (5<<12));
+    case 0x9: //DAC VClp 1
+      uart_word_to_dac(((thisRegister&0xFFFF)>>4) | (6<<12));
+     
+    case 0xF: //SPI Debug
+      uart_word_to_dac( (uint16_t) (thisRegister&0xFFFF));
+      break;
       
     case 0x11: // LEDs
       if(thisRegister & 1<<7) {
index 5cf462eca77c8d182baa1e245b35c4dd78a6ed11..769a8a690de716694f2e3d753dda0c0bf303f99e 100644 (file)
@@ -9,6 +9,7 @@ OBJS+=CB_functions.o
 OBJS+=usart1.o
 OBJS+=spi1.o
 OBJS+=spi2.o
+OBJS+=dac.o
 OBJS+=misc_utils.o
 
 # OBJS+=keypins.o
diff --git a/firmware/src/dac.c b/firmware/src/dac.c
new file mode 100644 (file)
index 0000000..ea5e5e6
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ ********************************************************
+ * 
+ *  USART3 (DAC)
+ * 
+ ********************************************************
+ */
+
+#include "dac.h"
+
+
+void init_USART3() {
+  GPIO_InitTypeDef GPIO_InitStructure;
+  USART_InitTypeDef USART_InitStructure;
+  USART_ClockInitTypeDef USART_ClkInitStructure;
+
+  /* Clock configuration -------------------------------------------------------*/
+  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
+  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
+  
+  /* Configure the GPIO ports( USART3 Transmit and Clock Lines) */
+  /* Configure as Alternate function remapped Push-Pull */
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  GPIO_Init(GPIOC, &GPIO_InitStructure);
+  GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
+  
+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_12;
+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+  GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+
+  /* USART1 configuration ------------------------------------------------------*/
+  /* USART1 configured as follow:
+  - BaudRate = 115200 baud  
+  - Word Length = 8 Bits
+  - One Stop Bit
+  - No parity
+  - Hardware flow control disabled (RTS and CTS signals)
+  - Receive and transmit enabled
+  */
+  USART_InitStructure.USART_BaudRate = 1000000;
+  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_Tx;
+
+  /* Configure the USART3 */
+  USART_Init(USART3, &USART_InitStructure);
+
+  USART_ClkInitStructure.USART_Clock=  USART_Clock_Enable;
+  USART_ClkInitStructure.USART_CPOL =  USART_CPOL_Low;
+  USART_ClkInitStructure.USART_CPHA =  USART_CPHA_1Edge;
+  USART_ClkInitStructure.USART_LastBit=USART_LastBit_Enable;
+  USART_ClockInit(USART3, &USART_ClkInitStructure);  
+  
+  /* Enable USART3 interrupt */
+  //USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
+  //USART_ITConfig(USART1,USART_IT_TXE,ENABLE);
+
+
+  /* Enable the USART3 */
+  USART_Cmd(USART3, ENABLE);
+  }
\ No newline at end of file
diff --git a/firmware/src/dac.h b/firmware/src/dac.h
new file mode 100644 (file)
index 0000000..3c49a29
--- /dev/null
@@ -0,0 +1,15 @@
+/**
+ ********************************************************
+ * 
+ *  DAC SPI (headers)
+ * 
+ ********************************************************
+ */
+  
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f10x.h"
+#include "stm32f10x_conf.h"
+
+
+void init_USART3(void);
\ No newline at end of file
index dc52a1743e1a0ea9a329354387975218a0cab847..2babe91932a3e239eb719321b7ae40c79bfd74aa 100644 (file)
@@ -16,6 +16,7 @@
 #include "CB_functions.h"
 #include "usart1.h"
 #include "spi2.h"
+#include "dac.h"
 #include "periph_conf.h"
 #include "misc_utils.h"
 
@@ -67,6 +68,7 @@ int main(int argc, char *argv[]) {
 
 
   init_USART1();
+  init_USART3();
   
   delay_ms(1000);
   CB_GPIO_Out_Hi(LED4);
index 71c5d6bad0402a2fb1fbbd0d9e4bc436082118ea..e1d84c28b7d45e5e208749fa164e455819178a0c 100644 (file)
@@ -54,4 +54,18 @@ uint8_t BufferOut(uint8_t *pByte) {
   *pByte = buffer.data[buffer.read];\r
   buffer.read = (buffer.read + 1) & BUFFER_MASK;\r
   return SUCCESS;\r
+}\r
+\r
+\r
+\r
+\r
+uint8_t reverse_8bit(uint8_t value) {\r
+  uint32_t t = __RBIT(value);\r
+  return t >> 24;\r
+}\r
+\r
+\r
+uint16_t reverse_16bit(uint16_t value) {\r
+  uint32_t t = __RBIT(value);\r
+  return t >> 16;\r
 }
\ No newline at end of file
index c3ffeaba1939f3934d7a8b7270c37613182fbeb2..9172eb93c59d419ac2a8862795d933a2a32cbb1a 100644 (file)
@@ -28,4 +28,8 @@ void SysTick_Handler(void);
 void delay_ms(uint16_t time_ms);\r
 \r
 uint8_t BufferIn(uint8_t byte);\r
-uint8_t BufferOut(uint8_t *pByte);
\ No newline at end of file
+uint8_t BufferOut(uint8_t *pByte);\r
+\r
+//Reverse value\r
+uint8_t reverse_8bit(uint8_t value);\r
+uint16_t reverse_16bit(uint16_t value);
\ No newline at end of file