#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);
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);
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) {
OBJS+=usart1.o
OBJS+=spi1.o
OBJS+=spi2.o
+OBJS+=dac.o
OBJS+=misc_utils.o
# OBJS+=keypins.o
--- /dev/null
+/**
+ ********************************************************
+ *
+ * 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
--- /dev/null
+/**
+ ********************************************************
+ *
+ * DAC SPI (headers)
+ *
+ ********************************************************
+ */
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f10x.h"
+#include "stm32f10x_conf.h"
+
+
+void init_USART3(void);
\ No newline at end of file
#include "CB_functions.h"
#include "usart1.h"
#include "spi2.h"
+#include "dac.h"
#include "periph_conf.h"
#include "misc_utils.h"
init_USART1();
+ init_USART3();
delay_ms(1000);
CB_GPIO_Out_Hi(LED4);
*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
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