Telechargé par radhia_a

SBMC2014

publicité
Ecole Nationale des Sciences de l’Informatique
A.U 2014-2015
Examen (Session Principale)
Module : Système à base de microcontrôleur
Durée : 2H
Enseignants: M. MASMOUDI
Date : 14 - 11 - 2014
Classe : 3ème SLE
Documents non autorisés
Exercice 1 (7 points)
1.
2.
3.
4.
Donner l’architecture interne d’un microcontrôleur. (1 pnt)
Décrire l’environnement minimal pour le fonctionnement d’un microcontrôleur. (1 pnt)
Dans un microcontrôleur, donner l’utilité d’avoir:
a. Plusieurs sources d’horloge. (0,5 pnt)
b. Plusieurs sources d’alimentation. (0,5 pnt)
c. Plusieurs modes de boot. (0,5 pnt)
d. Un bootloader. (0,5 pnt)
e. Un périphérique de gestion d’horloge. (0,5 pnt)
f. Plusieurs modes d’économie d’énergie. (0,5 pnt)
Donner l’instrumentation et les périphériques nécessaires pour :
a. La lecture d’une valeur analogique en tension. (0,5 pnt)
b. La lecture d’une valeur analogique en courant. (0,5 pnt)
c. Une mesure capacitive. (0,5 pnt)
d. Une sortie PWM. (0,5 pnt)
Problème (13 points)
Le SAE J1708 est un standard utilisé dans la communication entre les différents calculateurs dans les camions
poids lourd. SAE J1708 définit la couche physique dans le respect du modèle OSI. D’autre protocole sont utilisé
pour les couches supérieures. Le SAE J1708 utilise le même principe du RS485 en utilisant une transmission
différentielle de huit bits à 9600 bits par seconde avec un seul bit de start, un seul bit de stop, pas de parité et
sans contrôle matériel.
1.
1.1. C’est quoi la différence entre un protocole de communication asynchrone et un protocole de
communication synchrone. Le J1708 est un protocole synchrone ou asynchrone ? (1 pnt)
1.2. Justifier l’utilisation du J1708 dans cet environnement. (1 pnt)
Les deux fils de transmission du J1708 sont nommés A et B :


une transmission de la valeur 1 sur le bus revient à mettre le signal A à l’état haut et B à l’état
bas,
une transmission de la valeur 1 sur le bus revient à mettre le signal B à l’état haut et A à l’état
bas.
Le RS485 peut être transformé en UART juste en récupérant sur le fils Rx l’état du bus en mode réception, et on
synthétisant l’état du fils Tx sur le bus en cas d’émission. L’émission et la réception sont arbitrées par deux
signaux Re (receive enable) et De (Data transmission enable) .
2.
Ecrire les fonctions logique de :
2.1. Rx en fonction de A,B et Re en mode réception, (0.5 pnt)
2.2. A et B en fonction de Tx,De en cas d’émission. (0.5 pnt)
On opte pour utiliser un tranceiver MAX485 (voir figure) pour coupler un système à base d’un microcontrôleur
STM32 avec les bus J1708 en mode écoute (activer seulement la réception des caractères).
Figure 1: MAX485
3.
4.
5.
Faire les branchements nécessaires pour brancher le MAX 485 avec le stm32 en utilisant les pins PA9 en
tant que USART1_Tx et PA10 en tant que USART1_Rx. (1.5 pnt)
Ecrire les fonctions :
4.1. void J1708_gpioInit() ; permettant l’initialisation des GPIO utilisés. (1 pnt)
4.2. void J1708_usartInit() ; permettant l’initialisation de l’USART1 (initialisation des registres, activation,
activation de l’interruption). (1 pnt)
4.3. char J1708_receiveChar() ; permettant la réception d’un caractère depuis l’USART. (1 pnt)
Le standard SAE J1587 définie les couches supérieures pour quelques marques de véhicules. Dans ce cas,
un calculateur initie un envoie de trame une fois le bus est libre, envoie son identifiant MID, suivi par 0 à19
octets de données et fini par envoyer son checksum CS qui représente la somme arithmétique de tout les
octets de la trame. Le premier octet du champ des données représente l’identifiant de l’information
transmise PID.
La teille du champ data est égale à 2 si son premier octet est inférieur à 128 et 3 si 128<=PID<192,
sinon la taille de la trame est représentée par l’octet 2 du champ Data.
Un bus en état idle est défini par une absence de communication pendant au moins la durée
nécessaire pour envoyer 10 bits.
Figure 2: trame j1708/j1587
6.
5.1. Ecrire la fonction nécessaire pour utiliser le systick. (1 pnt)
5.2. En se référant sur les énumérations j1708State et j1708transition modéliser la machine à état de la
réception des données a travers le bus J1708. (1 pnt)
5.3. En utilisant la structure de donnée j1708, écrire les fonctions :
5.3.1. void j1708_init(j1708Struct * j1708) ; (0,5 pnt)
5.3.2. void j1708_routine(j1708Struct * j1708) ; (1,5 pnt)
5.3.3. void j1708_decrementDelay(j1708Struct * j1708) ; (0,5 pnt)
Ecrire le programme principale permettant la reception des trames j1708 et leurs décodage en utilisant la
fonction void J1708_Decode(char* j1708Data) ; (1 pnt)
Bon travail.
ANNEXES
}GPIO_InitTypeDef;
typedef enum{
GENERAL TYPEDEFS
Bit_RESET = 0,
typedef enum{
Bit_SET
ENABLE,
}BitAction;
DISABLE
//GPIO Pin
}FunctionalState;
…….
RCC FUNCTIONS
#define GPIO_Pin_8 ((uint16_t)0x0100)
/**
#define GPIO_Pin_9 ((uint16_t)0x0200)
@brief Enables or disables the High Speed APB (APB2) peripheral clock.
@param RCC_APB2Periph: specifies the APB2 peripheral to gates its #define GPIO_Pin_10 ((uint16_t)0x0400)
clock.This parameter can be any combination of the following values: #define GPIO_Pin_11 ((uint16_t)0x0800)
#define GPIO_Pin_12 ((uint16_t)0x1000)
@arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA,
#define GPIO_Pin_13 ((uint16_t)0x2000)
RCC_APB2Periph_GPIOB, RCC_APB2Periph_GPIOC,
#define GPIO_Pin_14 ((uint16_t)0x4000)
RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,
#define GPIO_Pin_15 ((uint16_t)0x8000)
RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG,
#define GPIO_Pin_All ((uint16_t)0xFFFF)
RCC_APB2Periph_ADC1,RCC_APB2Periph_ADC2,
GPIO FUNCTIONS
RCC_APB2Periph_TIM1,RCC_APB2Periph_SPI1,RCC_APB2Periph_TIM8,
RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3, RCC_APB2Periph_ALL
/** Deinitializes the GPIOx peripheral
registers to their default reset values.
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph,
* @param GPIOx: where x can be (A..G) to
FunctionalState NewState)
select the GPIO peripheral.
**/
GPIO TYPEDEFS AND DEFINE
void GPIO_DeInit(GPIO_TypeDef* GPIOx)
typedef enum{
/** Initializes the GPIOx peripheral
GPIO_Speed_10MHz = 1,
according to the specified
* parameters in the GPIO_InitStruct.
GPIO_Speed_2MHz,
* @param GPIOx: where x can be (A..G) to
GPIO_Speed_50MHz
select the GPIO peripheral.
}GPIOSpeed_TypeDef;
* @param GPIO_InitStruct: pointer to a
typedef enum{
GPIO_InitTypeDef structure that
GPIO_Mode_AIN = 0x0
* contains the configuration information
GPIO_Mode_IN_FLOATING = 0x04,
for the specified GPIO peripheral.
GPIO_Mode_IPD = 0x28,
**/
void GPIO_Init(GPIO_TypeDef* GPIOx,
GPIO_Mode_IPU = 0x48,
GPIO_InitTypeDef* GPIO_InitStruct)
GPIO_Mode_Out_OD = 0x14,
/** @brief Sets the selected data port bits.
GPIO_Mode_Out_PP = 0x10,
* @param GPIOx: where x can be (A..G) to
GPIO_Mode_AF_OD = 0x1C,
select the GPIO peripheral.
GPIO_Mode_AF_PP = 0x18
* @param GPIO_Pin: specifies the port bits
}GPIOMode_TypeDef;
to be written.
typedef struct{
* This parameter can be any combination
uint16_t GPIO_Pin;
of GPIO_Pin_x where x can be
(0..15).**/
GPIOSpeed_TypeDef GPIO_Speed;
GPIOMode_TypeDef GPIO_Mode;
SysTick FUNCTIONS
** \brief System Tick Configuration
The function initializes the System Timer and its interrupt, and starts
the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
For 1µs period ticks=SystemCoreClock/1000000
*/
uint32_t SysTick_Config(uint32_t ticks)
USART TYPEDEFS / DEFINE / FUNCTIONS
typedef struct
{
uint32_t USART_BaudRate;
uint16_t USART_WordLength;
uint16_t USART_StopBits;
uint16_t USART_Parity;
uint16_t USART_Mode;
uint16_t USART_HardwareFlowControl;
} USART_InitTypeDef;
/** @defgroup USART_Word_Length */
#define USART_WordLength_8b
((uint16_t)0x0000)
#define USART_WordLength_9b
((uint16_t)0x1000)
/** @defgroup USART_Stop_Bits */
#define USART_StopBits_1
((uint16_t)0x0000)
#define USART_StopBits_0_5
((uint16_t)0x1000)
#define USART_StopBits_2
((uint16_t)0x2000)
#define USART_StopBits_1_5
((uint16_t)0x3000)
/** @defgroup USART_Parity */
#define USART_Parity_No
((uint16_t)0x0000)
#define USART_Parity_Even
((uint16_t)0x0400)
#define USART_Parity_Odd
((uint16_t)0x0600)
/** @defgroup USART_Mode */
#define USART_Mode_Rx
((uint16_t)0x0004)
#define USART_Mode_Tx
((uint16_t)0x0008)
/** @defgroup USART_Hardware_Flow_Control */
#define USART_HardwareFlowControl_None
((uint16_t)0x0000)
#define USART_HardwareFlowControl_RTS
((uint16_t)0x0100)
#define USART_HardwareFlowControl_CTS
((uint16_t)0x0200)
#define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300)
/**
* @brief Deinitializes the USARTx peripheral registers to their
* default reset values.
* This parameter can be: ENABLE or DISABLE.
* @param USARTx: Select the USART or the UART peripheral.
* @retval : None
* This parameter can be one of the following values:
*/
* USART1, USART2, USART3, UART4 or UART5.
void USART_ITConfig(USART_TypeDef* USARTx, uint16_t
* @retval : None
USART_IT, FunctionalState NewState);
*/
/**
void USART_DeInit(USART_TypeDef* USARTx) ;
* @brief Returns the most recent received data by the USARTx
/**
peripheral.
* @brief Initializes the USARTx peripheral according to the specified
* @param USARTx: Select the USART or the UART peripheral.
* parameters in the USART_InitStruct .
* This parameter can be one of the following values:
* @param USARTx: Select the USART or the UART peripheral.
* USART1, USART2, USART3, UART4 or UART5.
* This parameter can be one of the following values:
* @retval : The received data.
* USART1, USART2, USART3, UART4 or UART5.
*/
* @param USART_InitStruct: pointer to a USART_InitTypeDef structure
uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
* that contains the configuration information for the
/**
* specified USART peripheral.
* @brief Checks whether the specified USART interrupt has
* @retval : None
occurred or not.
*/
* @param USARTx: Select the USART or the UART peripheral.
void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* * This parameter can be one of the following values:
USART_InitStruct) ;
* USART1, USART2, USART3, UART4 or UART5.
/**
* @param USART_IT: specifies the USART interrupt source to
* @brief Enables or disables the specified USART peripheral.
check.
* @param USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* This parameter can be one of the following values:
* @arg USART_IT_TXE: Tansmit Data Register empty interrupt
* USART1, USART2, USART3, UART4 or UART5.
* @arg USART_IT_TC: Transmission complete interrupt
* @param NewState: new state of the USARTx peripheral.
* @arg USART_IT_RXNE: Receive Data register not empty
* This parameter can be: ENABLE or DISABLE.
* @retval : The new state of USART_IT (SET or RESET).
* @retval : None
*/
*/
ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t
void USART_Cmd(USART_TypeDef* USARTx, FunctionalState
USART_IT);
NewState);
/**
/**
* @brief Clears the USARTx’s interrupt pending bits.
* @brief Enables or disables the specified USART interrupts.
* @param USARTx: Select the USART or the UART peripheral.
* @param USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* This parameter can be one of the following values:
* USART1, USART2, USART3, UART4 or UART5.
* USART1, USART2, USART3, UART4 or UART5.
* @param USART_IT: specifies the interrupt pending bit to clear.
* @param USART_IT: specifies the USART interrupt sources to
* This parameter can be one of the following values:
be
* @arg USART_IT_TC: Transmission complete interrupt.
* enabled or disabled.
* @arg USART_IT_RXNE: Receive Data register not empty
* This parameter can be one of the following values:
interrupt.
* @arg USART_IT_TXE: Tansmit Data Register empty interrupt
* /
* @arg USART_IT_TC: Transmission complete interrupt
void USART_ClearITPendingBit(USART_TypeDef* USARTx,
* @arg USART_IT_RXNE: Receive Data register not empty
uint16_t USART_IT);
* interrupt
J1708 Typedefs
* @param NewState: new state of the specified USARTx
interrupts.
typedef enum{
J1708_NO_TRANS=0 ;
J1708_IDLE_MID=0x01,
J1708_MID_DATA=0x02,
J1708_DATA_CS=0x04,
J1708_CS_IDLE=0x08,
J1708_DATA_IDLE=0x10,
J1708_MID_IDLE=0x20
}j1708Transition;
typedef enum{
J1708_IDLE J1708_MID,
J1708_Data,
J1708CHECKSUM
}j1708state;
typedef struct{
j1708State state;
j1708Transition trans;
uint8_t MID;
uint8_t PID;
char * Data[19] ;
uint8_t DataCursor ;
uint8_t CS ;
uint8_t validity;
…..
}j1708Struct;
Téléchargement