local time: :: ()
heure officielle (en France) : ::(TZ:)
Heure UTC client: :: Offset client: s - delai: ms - - timeZone: Heure UTC: ::This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:programs_to_communicate_with_the_dds [2016/03/14 08:47] fwiotte created |
en:programs_to_communicate_with_the_dds [2016/03/14 14:29] (current) fwiotte |
||
---|---|---|---|
Line 1: | Line 1: | ||
===Interface with TI microcontroller: the MSP430=== | ===Interface with TI microcontroller: the MSP430=== | ||
- | Sample program in C written in the microcontroller MSP430F169 | + | Sample program in C written in the microcontroller MSP430F169 this microcontroller has 2 SPI ports. |
- | + | ||
- | This microcontroller has 2 SPI ports. | + | |
SPI mode: Single-bit serial 2-wire Mode (default mode) | SPI mode: Single-bit serial 2-wire Mode (default mode) | ||
Line 39: | Line 37: | ||
Below under the boot program of the ports of the microcontroller and the SPI for the MSP430F169 TI provided numerous examples of base codes to configure the SPI modes, I2C and use the Flash memory: slac015p.zip | Below under the boot program of the ports of the microcontroller and the SPI for the MSP430F169 TI provided numerous examples of base codes to configure the SPI modes, I2C and use the Flash memory: slac015p.zip | ||
+ | |||
+ | void_init_SPI (void) | ||
+ | { | ||
+ | BCSCTL1 | = XTS; ACLK = = LFXT1 HF XTAL | ||
+ | BCSCTL2 | = SELM_3; MCLK = LFXT1 (safe) pine 8.9 of MSP430 | ||
+ | P1SEL = 0x00; P1 I / O select | ||
+ | P2SEL = 0x00; P2 I / O select | ||
+ | P3SEL = 0x00; P3 I / O select | ||
+ | P4SEL = 0x00; P4 I / O select | ||
+ | P5SEL = 0x0A; P5.1,3 SPI select option | ||
+ | P6SEL = 0x00; P6 I / O select | ||
+ | P1DIR = 0xFF; P1.output management | ||
+ | P2DIR = 0xFF; P2 output management | ||
+ | P3DIR = 0xFF; P3 output management | ||
+ | P4DIR = 0xFF; P4 output management | ||
+ | P5DIR = 0xFF; P5 output management | ||
+ | P6DIR = 0xFF; P6 output management | ||
+ | ME2 | = USPIE1; Enable SPI USART1 | ||
+ | UCTL1 | CHAR = + SYNC + MM; 8-bit SPI Master ** ** SWRST | ||
+ | UTCTL1 CKPH + = + SSEL1 STC; SMCLK delayed, 3-pin | ||
+ | UBR01 = 0x2; ACLK / 2 for baud rate | ||
+ | UBR11 = 0x0; ACLK / 2 for baud rate | ||
+ | UMCTL1 = 0x0; Clear modulation | ||
+ | UCTL1 & = ~ SWRST; Initialize USART state machine | ||
+ | } | ||
+ | BCSCTL1 | = XTS; and BCSCTL2 | = SELM_3; used to be the HF XTAL MSP430 operate at 8MHz instead of 32KHz default. | ||
+ | |||
+ | MSP430F169 | ||
+ | ----------------- | ||
+ | / | \ | XIN | - | ||
+ | | | | HF XTAL (455k - 8 Mhz) | ||
+ | - | RST XOUT | - | ||
+ | | | | ||
+ | | P5.4 | -> MCLK XTAL = | ||
+ | | ||
+ | |||
+ | According to Mr Buccini Texas Instruments Inc. Feb 2005 Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21a | ||
+ | |||
+ | the routine for loading data into SPI mode MSP430F169: | ||
+ | |||
+ | write_serial_port void (int instruction, long data, int num_byte) | ||
+ | { | ||
+ | int i = 0; | ||
+ | TXBUF1 = statement; | ||
+ | do | ||
+ | { | ||
+ | TXBUF1 = data >> (num_byte-1-i) * 8; | ||
+ | i ++; | ||
+ | } | ||
+ | while (i <num_byte); | ||
+ | } | ||
+ | ===Interface with a TI ARM microcontroller: the TM4C123GH6PM === | ||
+ | |||
+ | Example C program written in ARM microcontroller TM4C123GH6PM | ||
+ | |||
+ | This microcontroller has 4 SPI ports. Default = 80MHz clock | ||
+ | |||
+ | SPI mode: Single-bit serial 3-wire, the routine for the SPI mode data TM4C123GH6PM ARM: | ||
+ | |||
+ | |||
+ | int i = 0; | ||
+ | SSI0_DR_R = statement; | ||
+ | while (num_byte) | ||
+ | { | ||
+ | while (! (SSI0_SR_R & SSI_SR_TNF)) {} // SPI0 of TM4C123GH6PM | ||
+ | SSI0_DR_R = data >> (num_byte-1-i) * 8; | ||
+ | num_byte--; | ||
+ | } | ||
+ | |||
+ | while (! (SSI0_SR_R & SSI_SR_TNF)) | ||
+ | { | ||
+ | ; | ||
+ | } | ||
+ | | ||
+ | | ||
+ | |||
+ | The init routine (SPI) for the ARM TM4C123GH6PM: | ||
+ | |||
+ | // Enable Peripheral SSI0 | ||
+ | SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOA); // Enable GPIO port A SSI0. | ||
+ | SysCtlPeripheralEnable (SYSCTL_PERIPH_SSI0); | ||
+ | GPIOPinConfigure (GPIO_PA2_SSI0CLK); | ||
+ | GPIOPinConfigure (GPIO_PA3_SSI0FSS); | ||
+ | GPIOPinConfigure (GPIO_PA5_SSI0TX); | ||
+ | GPIOPinTypeSSI (GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_3 | GPIO_PIN_2); | ||
+ | // GPIOPinTypeSSI (GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_2); | ||
+ | SSIConfigSetExpClk (SSI0_BASE, SysCtlClockGet () SSI_FRF_MOTO_MODE_0, | ||
+ | SSI_MODE_MASTER, 10000000, 8); | ||
+ | SSIEnable (SSI0_BASE); // Enable the SSI | ||
+ | |||
+ | Example of initializing Port B on ARM TM4C123GH6PM: | ||
+ | |||
+ | // Void PortB_Init (void) | ||
+ | volatile unsigned long delay; | ||
+ | SYSCTL_RCGC2_R | = 0x00000002; // 1) activate clock for Port B | ||
+ | delay = SYSCTL_RCGC2_R; // Allow for time clock to start | ||
+ | GPIO_PORTB_AMSEL_R = 0x00; // 3) disable analog one PB | ||
+ | GPIO_PORTB_PCTL_R = 0x00000000; // 4) PCTL GPIO is PB0 | ||
+ | GPIO_PORTB_DIR_R | = 0xFF; // 5) PB0-PB7 is out | ||
+ | // GPIO_PORTB_AFSEL_R & = ~ 0x01; // 6) disable alt funct on PB0 | ||
+ | GPIO_PORTB_AFSEL_R & = ~ 0xFF; // 6) disable alt funct on PB0-PB7 | ||
+ | GPIO_PORTB_DEN_R | = 0xFF; // 7) enable digital I / O on PB0-PB7 | ||
+ | |||
+ | |||
+ | Example of initializing a USB-PORT for UART0 serial communication on the ARM TM4C123GH6PM: | ||
+ | |||
+ | // Void init_UART0 (void) | ||
+ | SysCtlPeripheralEnable (SYSCTL_PERIPH_UART0); | ||
+ | SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOA); | ||
+ | GPIOPinConfigure (GPIO_PA0_U0RX); | ||
+ | GPIOPinConfigure (GPIO_PA1_U0TX); | ||
+ | GPIOPinTypeUART (GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); | ||
+ | UARTConfigSetExpClk (UART0_BASE, SysCtlClockGet (), 9600, | ||
+ | (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); | ||
+ | |||
+ | | ||
+ | Example of declaration and initialization of the frequency word registers: | ||
+ | |||
+ | // // AD9852 | ||
+ | FTW0_ADRESS int = 0x02; | ||
+ | // Unsigned long long FTW0 = 0x17E4B17E4B1; //1.75MHz@300MHz clk | ||
+ | unsigned long long FTW0; | ||
+ | // Float FTW0 = 0x17E4B17E4B1; //1.75MHz@300MHz clk | ||
+ | FTW0_NUM_BYTE int = 0x06; | ||
+ | // // AD9858 | ||
+ | FTW1_ADRESS int = 0x03; | ||
+ | unsigned long FTW1 = 0x418937; // @ 1000MHz 1MHz clk | ||
+ | FTW1_NUM_BYTE int = 0x04; | ||
+ | // // AD9858 | ||
+ | CFR_ADRESS int = 0x00; | ||
+ | unsigned long CFR = 0x79; // MSB first | ||
+ | CFR_NUM_BYTE int = 0x04; |