MAXREFDES62# Code Documentation  V01.00
RS-485 Micro PLC
 All Files Functions Variables Macros Pages
maxim_device_specific_utilities.c
Go to the documentation of this file.
1 
31 /*
32 * Copyright (C) 2012 Maxim Integrated Products, Inc., All Rights Reserved.
33 *
34 * Permission is hereby granted, free of charge, to any person obtaining a
35 * copy of this software and associated documentation files (the "Software"),
36 * to deal in the Software without reps_striction, including without limitation
37 * the rights to use, copy, modify, merge, publish, dips_stribute, sublicense,
38 * and/or sell copies of the Software, and to permit persons to whom the
39 * Software is furnished to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
44 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
45 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47 * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
48 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
49 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
50 * OTHER DEALINGS IN THE SOFTWARE.
51 *
52 * Except as contained in this notice, the name of Maxim Integrated Products
53 * shall not be used except as stated in the Maxim Integrated Products
54 * Branding Policy.
55 *
56 * The mere transfer of this software does not imply any licenses
57 * of trade secrets, proprietary technology, copyrights, patents,
58 * trademarks, maskwork rights, or any other form of intellectual
59 * property whatsoever. Maxim Integrated Products retains all ownership rights.
60 *
61 ***************************************************************************/
62 
64 #include "stm32f10x_gpio.h"
65 #include "stm32f10x_spi.h"
66 
67 uint8_t maxim_keypress_loopback(uint8_t uch_char)
79 {
80  uint8_t uch_input;
81  uint8_t u_value;
82 
83  GPIO_SetBits(GPIOA, GPIO_Pin_1); //EN = 1
84  while(1)
85  {
86  uch_input=USART_ReceiveData(USART3); //Clear USART3 RX buffer
87  USART_SendData(USART2,uch_char); //transmit a character with MAX14783
88  while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
89  while(USART_GetFlagStatus(USART3,USART_FLAG_RXNE)==RESET) //if the data doesn't return within four cycles, assert fault condition
90  {
91  u_value++;
92  if(u_value>3)
93  break;
94  }
95  if(u_value>3)
96  return FAIL;
97  uch_input=USART_ReceiveData(USART3); //receive a character with MAX14789E
98  USART_SendData(USART1,uch_input);
99  if(uch_input!=uch_char)
100  return FAIL;
101  return PASS;
102  }
103 }
104 
116 {
117  uint8_t uch_input, uch_output, uch_ret;
118  uint32_t un_count;
119  uch_ret=PASS;
120  GPIO_SetBits(GPIOA, GPIO_Pin_1); //EN = 1
121  uch_input=USART_ReceiveData(USART3); //Clear USART3 RX buffer
122  while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET);
123  while(1)
124  {
125  un_count=0;
126  while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET)
127  {
128  un_count++;
129  if(un_count>1000000) //test for end of file
130  {
131  return uch_ret;
132  }
133  }
134  uch_output=USART_ReceiveData(USART1); //receive a character from the terminal program
135  USART_SendData(USART2,uch_output); //transmit a character with MAX14783
136  while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
137  un_count=0;
138  while(USART_GetFlagStatus(USART3,USART_FLAG_RXNE)==RESET) //if the data doesn't return within four cycles, assert fault condition
139  {
140  un_count++;
141  if(un_count>3)
142  break;
143  }
144  if(un_count>3)
145  uch_ret=FAIL;
146  uch_input=USART_ReceiveData(USART3); //receive a character with MAX14789E
147  USART_SendData(USART1,uch_input);
148  if(uch_input!=uch_output)
149  uch_ret=FAIL;
150  }
151 }