Guest User

Untitled

a guest
May 15th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. #include "libmaple.h"
  7. #include "boards.h"
  8. #include "gpio.h"
  9. #include "delay.h"
  10. #include "usart.h"
  11. #include "dma.h"
  12. #include "queue.h"
  13.  
  14. #define LEV_SENSE_I2C_ADDR  0x55
  15. #define TEMP_SENSE_I2C_ADDR 0x48
  16.  
  17. #define STR_SIZE 11
  18. uint8 tx_buf[STR_SIZE];
  19.  
  20. // Force init to be called *first*, i.e. before static object allocation.
  21. // Otherwise, statically allocated objects that need libmaple may fail.
  22. __attribute__((constructor)) void premain() {
  23.     init();
  24. }
  25.  
  26. static void dma_handler()
  27. {
  28.     dma_disable(DMA1, DMA_CH1);
  29. }
  30.  
  31. int main(void)
  32. {
  33.     gpio_set_mode(GPIOB, 3, GPIO_OUTPUT_PP);
  34.    
  35.     usart_init(USART1);
  36.     usart_set_baud_rate(USART1, PCLK2, 115200);
  37.     usart_enable(USART1);
  38.     USART1->regs->CR3 |= USART_CR3_DMAT;
  39.  
  40.     snprintf(tx_buf, STR_SIZE-1, "test dma\r\n");
  41.    
  42.     dma_init(DMA1);
  43.     dma_mode_flags fl = (DMA_FROM_MEM | DMA_MINC_MODE | DMA_TRNS_CMPLT);
  44.     dma_setup_transfer(DMA1, DMA_CH1, &(USART1->regs->DR), DMA_SIZE_8BITS, tx_buf, DMA_SIZE_8BITS, fl);
  45.     dma_set_num_transfers(DMA1, DMA_CH1, STR_SIZE);
  46.     dma_attach_interrupt(DMA1, DMA_CH1, dma_handler);
  47.     dma_enable(DMA1, DMA_CH1);
  48.    
  49.     uint8 toggle = 0;
  50.     while(1) {
  51.         if (toggle == 0)
  52.             toggle = 1;
  53.         else
  54.             toggle = 0;
  55.         gpio_write_bit(GPIOB, 3, toggle);
  56.         delay_s(1);
  57.     }
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment