Difference between revisions of "GPS RECEIVER - MT3329"
From Teknologisk videncenter
m (→Module on MCBSTM32C Keil board) |
m (→Module on MCBSTM32C Keil board) |
||
Line 18: | Line 18: | ||
==USART 1 code== | ==USART 1 code== | ||
− | + | Communication with the GPS module has been achieved through expansion of the Keil RTX_Blinky example. This code is written uVision4. | |
− | + | ||
− | |||
<source lang=c> | <source lang=c> | ||
int main (void) | int main (void) |
Revision as of 08:34, 22 October 2014
Contents
Module on MCBSTM32C Keil board
Using the STM32F107VC remapped USART1 to PB6 (USART1_TX)and PB7 (USART1_RX). The GPS module uses VCC and GND and not RS232 levels on TX/RX. Five boards are modified for the five GPS modules bought.
- The [1] show that PB6 is used for CAN2 bus TX. CAN2 bus can't be used at the same time as the GPS module.
- The [2] show that PB7 is used for the USER button. To use PB7 as RX from the GPS module it is necessary to remove C20. The USER switch can't be used at the same time as the GPS module.
Connections
Solder a 6 pin 0,1 inch 90 degrees angle. See picture 2 and connect
- Pin 1 to 3,3V (Red wire)
- Pin 2 to GND (Black wire)
- Pin 3 - Not used in this project ( 1 second pulse signal from GPS module )
- Pin 4 to PB7 (Orange wire) - GPS module TX
- Pin 5 to PB6 (Yellow wire) - GPS module RX
- Pin 6 - NOt used in this project ( FIX signal )
Battery connector on keil board
The minus pole on the battery has no electrical connection to the main board. To make a connection a desisolated wire was placed between the minuspole on the battery and the goldplated area on the PCB under the battery. See picture 2.
USART 1 code
Communication with the GPS module has been achieved through expansion of the Keil RTX_Blinky example. This code is written uVision4.
int main (void)
{
SystemInit(); /* initialize clocks */
/* Setup GPIO for LEDs */
RCC->APB2ENR |= 1 << 6; /* Enable GPIOE clock */
GPIOE->CRH = 0x33333333; /* Configure the GPIO for LEDs */
GLCD_Init(); /* Initialize the GLCD */
GLCD_Clear(White); /* Clear the GLCD */
//Enable Port B clock and configure USART1 (with remapping of USART1 to Port B from Port A)
RCC->APB2ENR |= 1 << 3;
RCC->CFGR |= 4 << 10;
RCC->APB2ENR |= 1 << 0;
AFIO->MAPR |= 1 << 2;
//Enable GPIOB7 as rx, GPIOB6 as tx (Pin7: 0100, Pin6: 1011)
GPIOB->CRL &= 0x00FFFFFF;
GPIOB->CRL |= 0x4B000000;
//Enable USART in RCC_APB2ENR
RCC->APB2ENR |= 1 << 14;
/*
Set baud rate (USART_BRR): BaudRate = fck / ( 16 * USARTDIV )
For example:
fck = 72 MHz
required Baud Rate = 9600
USARTDIV = fck/(16 * BaudRate ) = 72000000/(16 * 9600) = 468.75
Mantissa = 438 - as hex: 0x1D4
Fraction = 16*0.75 = 12 - as hex: 0xC
See Reference Manual for further details
*/
USART1->BRR = 0x01d4c;
//USART enable
USART1->CR1 |= 1 << 13;
//USART Tx enable
USART1->CR1 |= 1 << 3;
//USART Rx enable
USART1->CR1 |= 1 << 2;
//USART Rx Interrupt enable
USART1->CR1 |= 1 << 5;
//Send initialisation messages to the GPS, 1: Baud rate, 2: Reset GPS to output default NMEA messages
putstr("PMTK251,9600*17\r\n");
putstr("PMTK314,-1*04\r\n");
NVIC_EnableIRQ(USART1_IRQn);
os_sys_init (init); /* Initialize RTX and start init */
}
void usart1_tx(char character)
{
while ((USART1->SR & ( 1 << 6)) == 0) {}; // Wait HSERDY = 1
USART1->DR = (uint16_t) character;
}
void putstr(char *string)
{
int i;
for ( i=0; string[i] != 0; i++ )
{
usart1_tx(string[i]);
}
}
//USART1 Interrupt Handler
void USART1_IRQHandler(void) __irq
{
NVIC_DisableIRQ(USART1_IRQn);
//Send event flag to t_gps task
isr_evt_set(0x1111, t_gps);
//Reset USART status register to allow the next value from the serial link to be set
USART1->SR &= ~(1 << 5);
NVIC_EnableIRQ(USART1_IRQn);
}
Data sheets
ARM board projects