Is it possible to change Asynchronous Slave ID from software?
Let me explain: is it possible to attribute a value (read for example by an external dip switch) to the slave address ID of an asynchronous port?
Thank you
Hello,
I use UART and I confirm that I would like to be able to assign the Slave code from DipSw so that I can exchange slave devices without having to reprogram the 'Slave Id' property.
I noticed a possibility by changing the code of 'ASl1.c' generated by Processor Expert.
If I insert an external variable visible from 'main.c' called, for example, Code_Id in the code ASl1.c and subsequently modifying the method 'ASl1_AsynchroSeSl (component AsynchroSlave)' like so:
** This component module is generated by Processor Expert. Do not modify it.
/*!
** @file ASl1.c
** @version 01.33
** @brief
** This component "AsynchroSlave" implements SLAVE part of asynchronous
** serial master-slave communication.
*/
/*!
** @addtogroup ASl1_module ASl1 module documentation
** @{
*/
/* MODULE ASl1. */
/* SerFlag bits */
#define OVERRUN_ERR 0x01U /* Overrun error flag bit */
#define COMMON_ERR 0x02U /* Common error of RX */
#define CHAR_IN_RX 0x04U /* Char is in RX buffer */
#define FULL_TX 0x08U /* Full transmit buffer */
static volatile byte SerFlag; /* Flags for serial communication */
/* Bit 0 - Overrun error */
/* Bit 1 - Common error of RX */
/* Bit 2 - Char in RX buffer */
/* Bit 3 - Full TX buffer */
static ASl1_TComData BufferRead; /* Input char for SCI commmunication */
static bool SelSlave; /* Device is selected */
static void AsynchroSeSl(byte *Flg, byte Num); /* Prototype of the function AsynchroSeSl */
extern byte Code_Id; // New external variable
.
.
.
.
/*
** ===================================================================
** Method : ASl1_AsynchroSeSl (component AsynchroSlave)
**
** Description :
** Compares the received Slave ID with it's own ID and sets the
** appropriate flags.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void AsynchroSeSl(byte *Flg, byte Num)
{
if (Num == ASl1_SLAVE_ID) { /* Is Num parametr equal as address of slave? */
if (Num == Code_Id) { // I replace the constant 'ASl1_SLAVE_ID' with my external variable
*Flg |= ON_SELECT; /* Set flag */
SelSlave = TRUE; /* Slave is selected */
} else {
if (SelSlave == TRUE) { /* Is slave selected? */
*Flg |= ON_UNSELECT; /* Set flag */
}
SelSlave = FALSE; /* Slave is not selected */
}
}
It might work, I haven't tried it yet ...:smileywink:
Hi Vicente,
I am using S912ZVCA192 as master which should communicate with a group of slave devices (9s08sh8) to which I would like to be able to assign them an address by dip switch.
Thanks for your interest
Hi
Can you please tell me the protocol that you are using, UART, LIN SPI, IIC?
I believe that you want to use other pins (GPIOs) to set the address and then use the protocols to make the communication, is this correct?
Regards
Vicente
Can you please tell us the device that you are using?
regards