Hello,
I am trying to write a character to a specific IO pin but no success . So, I have the following pieces of code (I mention that I have modified the BSP lib in order to have access to this specific pins) :
const uint_32 output_set[] = { TX_PIN, TX_ENABLE, GPIO_LIST_END };output = fopen("gpio:write", (char_ptr) &output_set);if (output){ SetOutput();}else printf("Error\n");.......
the SetOutput function :
void SetOutput(void){ static const uint_32 TxPin[] = { TX_PIN, GPIO_LIST_END }; static const uint_32 TxEnable[] = { TX_ENABLE, GPIO_LIST_END }; ioctl(output, 1, (pointer) &TxPin); ioctl(output, 1, (pointer) &TxEnable);}
Debugging the program , I've seen that it is a problem with fopen function (I think). As you can see in the printscreen attached : it reaches that breakpoint and never steps out.
Can anyone have an idea ? What I am doing wrong.. ?
Thanks
Solved! Go to Solution.
Thanks for your reply!
It seemed to be a hardware problem (not correctly connected to the I/O pins).
Right now, I am trying to send a char using RS-485 (4 wires). So, I have Rx, Tx, RxEnable, TxEnable. Maybe you can give a hint regarding this topic because I think I missed something (based on the fact I am a beginner with MQX).
I have the defines :
#define TxPin BSP_TX#define RxPin BSP_RX#define Tx_Enable BSP_TX_ENABLE#define Rx_Enable BSP_RX_ENABLE
Initialize function :
boolean InitializeIO(void) { const uint_32 output_set[] = { TxPin | GPIO_PIN_STATUS_0, Tx_Enable | GPIO_PIN_STATUS_0, Rx_Enable | GPIO_PIN_STATUS_0, GPIO_LIST_END }; const uint_32 input_set[] = { RxPin, GPIO_LIST_END }; /* Open and set port as output */ output_port = fopen("gpio:write", (char_ptr) output_set); /* Open and set port as input to read value from Rx pin*/ input_port = fopen("gpio:read", (char_ptr) input_set); if (output_port && input_port) return (input_port!=NULL) && (output_port!=NULL); else return 0;}
Then I am trying to setup the outputs (for transmitting - RxEnable 1 and TxEnable 1 :
void SetOutput(int signal) { uint_32 set_value=0; static const uint_32 Send[] = { TxPin, GPIO_LIST_END }; static const uint_32 SendEnable[] = { Tx_Enable, GPIO_LIST_END }; static const uint_32 ReceiveEnable[] = { Rx_Enable, GPIO_LIST_END }; if(output_port) { switch(signal) { case 1: ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, (pointer) &Send); case 2: { ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, (pointer) &SendEnable); ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, (pointer) &ReceiveEnable); } } } }
And the trying to send the character :
int SendChar(uchar c){ _mqx_int error=0; SetOutput(2); ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, NULL); error = fputc(c,output_port); _time_delay(100); return error;}
Any hint ? What I am doing wrong ?
Many thanks
Are you using magic numbers?
This works for me.
When I send a character I start a timer after setting the enable pin. The timer times out and resets the pin for me.
#define GPIO_IOCTL_WRITE_LOG1 _IO(IO_TYPE_GPIO,0x02) /* Set pins on output port */
#define GPIO_IOCTL_WRITE_LOG0 _IO(IO_TYPE_GPIO,0x03) /* Clear (set to 0) pins on output port */
GPIO_PIN_STRUCT ch1_ps[] = { CH1_TX_ENABLE, GPIO_LIST_END }; FILE_PTR ch1_enable_fh;......//initializationch1_enable_fh = fopen("gpio:write", ch1_ps );//use in the serial send routine_mqx_int unc1_putc(uchar c){ _mqx_int err; err = 0; if(socket_flag && sockfd != NULL) { err = fputc(c,sockfd); } else if(application_list[HOST_APP] !=0) { ioctl(ch1_enable_fh, GPIO_IOCTL_WRITE_LOG1, NULL); err = fputc(c,ch1_fh); uart1_timer = (40000 / uart1_baud) +1; while(uart1_timer) _time_delay(10); } return (err);}//timer times out if(uart1_timer) if(! -- uart1_timer) { ioctl(ch1_enable_fh, GPIO_IOCTL_WRITE_LOG0, NULL); }
Thanks for your reply!
It seemed to be a hardware problem (not correctly connected to the I/O pins).
Right now, I am trying to send a char using RS-485 (4 wires). So, I have Rx, Tx, RxEnable, TxEnable. Maybe you can give a hint regarding this topic because I think I missed something (based on the fact I am a beginner with MQX).
I have the defines :
#define TxPin BSP_TX#define RxPin BSP_RX#define Tx_Enable BSP_TX_ENABLE#define Rx_Enable BSP_RX_ENABLE
Initialize function :
boolean InitializeIO(void) { const uint_32 output_set[] = { TxPin | GPIO_PIN_STATUS_0, Tx_Enable | GPIO_PIN_STATUS_0, Rx_Enable | GPIO_PIN_STATUS_0, GPIO_LIST_END }; const uint_32 input_set[] = { RxPin, GPIO_LIST_END }; /* Open and set port as output */ output_port = fopen("gpio:write", (char_ptr) output_set); /* Open and set port as input to read value from Rx pin*/ input_port = fopen("gpio:read", (char_ptr) input_set); if (output_port && input_port) return (input_port!=NULL) && (output_port!=NULL); else return 0;}
Then I am trying to setup the outputs (for transmitting - RxEnable 1 and TxEnable 1 :
void SetOutput(int signal) { uint_32 set_value=0; static const uint_32 Send[] = { TxPin, GPIO_LIST_END }; static const uint_32 SendEnable[] = { Tx_Enable, GPIO_LIST_END }; static const uint_32 ReceiveEnable[] = { Rx_Enable, GPIO_LIST_END }; if(output_port) { switch(signal) { case 1: ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, (pointer) &Send); case 2: { ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, (pointer) &SendEnable); ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, (pointer) &ReceiveEnable); } } } }
And the trying to send the character :
int SendChar(uchar c){ _mqx_int error=0; SetOutput(2); ioctl(output_port, GPIO_IOCTL_WRITE_LOG1, NULL); error = fputc(c,output_port); _time_delay(100); return error;}
Any hint ? What I am doing wrong ?
Many thanks