diff --git a/Makefile b/Makefile index 8154d05..09a66f8 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,9 @@ $(OBJECTS8): $(SOURCES8) @cp ch395-8.lib build/lib8/ @cp ch395-8.lib target/telestrat/lib/ +test: + $(CC) -ttelestrat -I src/include test/ch395.c target/telestrat/lib/ch395-8.lib -o ch395 + tool: @mkdir -p target/telestrat/ch395cfg/ $(CC) -ttelestrat -I src/include tools/ch395cfg/src/main.c target/telestrat/lib/ch395-8.lib -o target/telestrat/ch395cfg/ch395cfg diff --git a/docs/api/2024.2/assembly/index.html b/docs/api/2024.2/assembly/index.html index 7d2a036..f26d4e0 100644 --- a/docs/api/2024.2/assembly/index.html +++ b/docs/api/2024.2/assembly/index.html @@ -1316,7 +1316,7 @@
Description
-This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index
+This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:
Input
Description
-Open socket from arg
+This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.
Input
Description
-Set dest port socket
+This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.
Input
Description
-Set Socket Ip address to connect with
+This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
Input
Modify
Description
@@ -1645,6 +1648,15 @@Description
+This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:
+Code Name Description
+03H PROTO_TYPE_TCP TCP mode
+02H PROTO_TYPE_UDP UDP mode
+01H PROTO_TYPE_MAC_RAW MAC original message mode
+00H PROTO_TYPE_IP_RAW IP original message mode
+This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference
+Steps for detailed steps.
Input
Modify
+Description
@@ -1679,7 +1695,7 @@Description
-Set source port
+This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.
Input
Modify
+Input
@@ -1714,11 +1734,11 @@Description
-TCP listen socket
+This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.
Description
-Send data to socketid
+This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again
Input
Modify
Example
+
+
Description
-Checks if ch395 exists
+This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
@@ -1047,7 +1047,26 @@Get General interrupt Status
Description
-Get ch395 firmware version
+;;@brief This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
+;;@inputA Socket id
+ ;;@modifyA
+ ;;@modifyX
+ ;;@returnsA Status of selected socket
+ ;;@ca65
+ ;;@` lda #CH395_SOCKET1 ; Check socket 1
+ ;;@` jsr ch395_get_int_status_sn
+ ;;@` ; Check interrupt type
+ ;;@` and #CH395_SINT_STAT_SEND_OK
+ ;;@` cmp #CH395_SINT_STAT_SEND_OK
+ ;;@` beq @send_ok
+ ;;@` rts
+ ;;@
+ldx #CH395_GET_INT_STATUS_SN
+ stx CH395_COMMAND_PORT
+ sta CH395_DATA_PORT
+ lda CH395_DATA_PORT
+ rts
+endproc
Description
Check interrupt socket status
@@ -1093,7 +1112,7 @@Description
Set gateway ip addr
Description
-Set ip addr
+This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
Description
diff --git a/docs/api/assembly/index.html b/docs/api/assembly/index.html index f6ab860..fc4b884 100644 --- a/docs/api/assembly/index.html +++ b/docs/api/assembly/index.html @@ -970,7 +970,7 @@Description
-This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index
+This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:
Input
Description
-Open socket from arg
+This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.
Input
Description
-Set dest port socket
+This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.
Input
Description
-Set Socket Ip address to connect with
+This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
Input
Modify
Description
@@ -1299,6 +1302,15 @@Description
+This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:
+Code Name Description
+03H PROTO_TYPE_TCP TCP mode
+02H PROTO_TYPE_UDP UDP mode
+01H PROTO_TYPE_MAC_RAW MAC original message mode
+00H PROTO_TYPE_IP_RAW IP original message mode
+This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference
+Steps for detailed steps.
Input
Modify
+Description
@@ -1333,7 +1349,7 @@Description
-Set source port
+This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.
Input
Modify
+Input
@@ -1368,11 +1388,11 @@Description
-TCP listen socket
+This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.
Description
-Send data to socketid
+This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again
Input
Modify
Example
+
+
Description
-Checks if ch395 exists
+This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
@@ -764,7 +764,26 @@Get General interrupt Status
Description
-Get ch395 firmware version
+;;@brief This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
+;;@inputA Socket id
+ ;;@modifyA
+ ;;@modifyX
+ ;;@returnsA Status of selected socket
+ ;;@ca65
+ ;;@` lda #CH395_SOCKET1 ; Check socket 1
+ ;;@` jsr ch395_get_int_status_sn
+ ;;@` ; Check interrupt type
+ ;;@` and #CH395_SINT_STAT_SEND_OK
+ ;;@` cmp #CH395_SINT_STAT_SEND_OK
+ ;;@` beq @send_ok
+ ;;@` rts
+ ;;@
+ldx #CH395_GET_INT_STATUS_SN
+ stx CH395_COMMAND_PORT
+ sta CH395_DATA_PORT
+ lda CH395_DATA_PORT
+ rts
+endproc
Description
Check interrupt socket status
@@ -810,7 +829,7 @@Description
Set gateway ip addr
Description
-Set ip addr
+This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
Description
diff --git a/docs/api/search/search_index.json b/docs/api/search/search_index.json index 7f3ed25..e13a387 100644 --- a/docs/api/search/search_index.json +++ b/docs/api/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Introduction","text":"This lib is used to manage ch395 chip for 6502 cpu
"},{"location":"assembly/","title":"Assembly","text":""},{"location":"assembly/#assembly","title":"Assembly","text":""},{"location":"assembly/#ch395_check_exist","title":"ch395_check_exist","text":"Description
This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
Modify
Returns
Example
jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
"},{"location":"assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
Input
Modify
Example
lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
"},{"location":"assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
Modify
Example
lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
"},{"location":"assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Input
Modify
Description
This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.
Does not work
"},{"location":"assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"Description
This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:
Example
jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n
Modify
Description
Get dhcp status
Example
jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n
Modify
Description
This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Does not work
"},{"location":"assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"Description
This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Bit Name Description
7 GINT_STAT_SOCK3 Socket3 interrupt
6 GINT_STAT_SOCK2 Socket2 interrupt
5 GINT_STAT_SOCK1 Socket1 interrupt
4 GINT_STAT_SOCK0 Socket0 interrupt
3 GINT_STAT_DHCP DHCP interrupt
2 GINT_STAT_PHY_CHANGE PHY status change interrupt
1 GINT_STAT_IP_CONFLI IP conflict
0 GINT_STAT_UNREACH Inaccessible interrupt
\u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt
message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible
information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the
command GET_UNREACH_IPPORT to get the inaccessible information.
\u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its
IP address is the same as that of other network devices in the same network segment.
\u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection
of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or
from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get
the current PHY connection status.
\u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate
this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the
status is 0, it will indicate success; otherwise, it will indicate timeout failure.
\u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in
Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the
interrupt status of Socket. Please refer to GET_INT_STATUS_SN.
When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt
status
Modify
Returns
Example
jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
"},{"location":"assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"Description
This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
Modify
Returns
Example
jsr ch395_get_ic_ver\n; Check A for version\nrts\n
"},{"location":"assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"Description
This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index
Input
Modify
Returns
Example
lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
"},{"location":"assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"Description
Get ip info
Input
Modify
Description
Get mac address
Input
Modify
Returns
Accumulator : the content of ptr modified
X Register : the content of ptr modified
Description
This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H
Modify
Returns
Example
jsr ch395_get_phy_status\n; Check A physical status\nrts\n
"},{"location":"assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"Description
Get the length received from socket
Input
Example
lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n
Modify
Returns
Accumulator : The length
X Register : The length
Description
This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command
Input
Modify
Example
lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
"},{"location":"assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"Description
This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:
Input
Modify
Returns
Accumulator : The status
X Register : The state
Example
lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
"},{"location":"assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"Description
This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).
Does not work
"},{"location":"assembly/#ch395_init","title":"ch395_init","text":"Description
This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.
Modify
Reset ch395
Example
jsr ch395_init\n; Wait a bit\n
"},{"location":"assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"Description
Open socket from arg
Input
Modify
Description
Get buffer from socket
Input
Modify
Description
This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.
Example
jsr ch395_reset_all\n; Wait a bit\n
"},{"location":"assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"Description
This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.
"},{"location":"assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"Description
Set dest port socket
Input
Modify
Example
lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
"},{"location":"assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"Description
Set fun para
Input
Modify
Description
This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address
Does not work
"},{"location":"assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"Description
This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below
Does not work
"},{"location":"assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"Description
Set Socket Ip address to connect with
Input
Description
Set ipraw protocol on socket
Input
Modify
Description
This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address
Input
Modify
Does not work
"},{"location":"assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"Description
This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set
Does not work
"},{"location":"assembly/#ch395_set_phy","title":"ch395_set_phy","text":"Description
This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.
Does not work
"},{"location":"assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"Input
Description
This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.
Input
Description
This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.
Input
Modify
Example
lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
"},{"location":"assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"Description
Set source port
Input
Modify
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
Input
Input
Input
Description
TCP listen socket
"},{"location":"assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"Description
Send data to socketid
Input
Modify
Description
Checks if ch395 exists
"},{"location":"c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
"},{"location":"c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
"},{"location":"c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Description
Get cmd status
"},{"location":"c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"Description
Get dhcp status
"},{"location":"c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"Description
Get General interrupt Status
"},{"location":"c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"Description
Get ch395 firmware version
"},{"location":"c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"Description
Check interrupt socket status
Input
"},{"location":"c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"Description
Get ip info
"},{"location":"c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"Description
Get mac address
"},{"location":"c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"Description
Get physical status
"},{"location":"c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"Description
Get the length received from socket
Input
"},{"location":"c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"Description
Get remote ip connected to the socket
Input
"},{"location":"c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"Description
Returns in A socket status (close/open ... )
Input
"},{"location":"c/#void-ch395_init","title":"void ch395_init();","text":"Description
Initialize ch395
"},{"location":"c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"Input
"},{"location":"c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"Description
Reset ch395
"},{"location":"c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"Description
Set dest port socket
Input
"},{"location":"c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"Description
Set fun para
Description
Set gateway ip addr
Description
Set ip addr
"},{"location":"c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"Description
Set ipraw protocol on socket
Input
"},{"location":"c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"Description
Set retran period
"},{"location":"c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"Description
Retran period
"},{"location":"c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"Description
Set source socket
Input
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
"},{"location":"c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Description
Send data to socketid [Not working]
Input
"},{"location":"2024.1/assembly/","title":"Assembly","text":""},{"location":"2024.1/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.1/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"Description
Checks if ch395 exists
Example
jsr ch395_get_glob_int_status\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
Modify
Returns
Description
Clear receive buffer
Input
Modify
Example
lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
"},{"location":"2024.1/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"Description
Close socket
Input
Modify
Example
lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
"},{"location":"2024.1/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"Description
Enable or not dhcp
Input
Modify
Description
Get cmd status
Example
jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n
Modify
Description
Get dhcp status
Example
jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n
Modify
Description
Get General interrupt Status
Modify
Example
jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
"},{"location":"2024.1/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"Description
Get ch395 firmware version
Example
jsr ch395_get_ic_ver\n; Check A for version\nrts\n
Modify
Description
Check interrupt socket status
Input
Modify
Returns
Example
lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nrts\n
"},{"location":"2024.1/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"Description
Get ip info
Input
Modify
Description
Get mac address
Input
Modify
Returns
Accumulator : the content of ptr modified
X Register : the content of ptr modified
Description
Get physical status
Modify
Returns
Example
jsr ch395_get_phy_status\n; Check A physical status\nrts\n
"},{"location":"2024.1/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"Description
Get the length received from socket
Input
Example
lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n
Modify
Returns
Accumulator : The length
X Register : The length
Description
Get remote ip connected to the socket
Input
Modify
Description
Returns in A socket status (close/open ...)
Input
Modify
Returns
Accumulator : The status
X Register : The state
Example
lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\n
"},{"location":"2024.1/assembly/#ch395_init","title":"ch395_init","text":"Description
Initialize ch395
Modify
Reset ch395
Example
jsr ch395_init\n; Wait a bit\n
"},{"location":"2024.1/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"Description
Open socket from arg
Input
Modify
Input
Description
Reset ch395
Example
jsr ch395_reset_all\n; Wait a bit\n
"},{"location":"2024.1/assembly/#ch395_retran_period","title":"ch395_retran_period","text":"Description
Retran period
Input
Modify
Example
lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
"},{"location":"2024.1/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"Description
Set dest port socket
Input
Example
lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
"},{"location":"2024.1/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"Description
Set fun para
Input
Modify
Description
Set gateway ip addr
"},{"location":"2024.1/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"Description
Set ip row
"},{"location":"2024.1/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"Description
Set Socket Ip address to connect with
Input
Description
Set ipraw protocol on socket
Input
Description
Set mac address
"},{"location":"2024.1/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"Input
Description
Set retran period
Input
Input
Input
Input
Description
TCP listen socket
"},{"location":"2024.1/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"Description
Send data to socketid
Input
Description
Checks if ch395 exists
"},{"location":"2024.1/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"Description
Clear receive buffer
"},{"location":"2024.1/c/#oid-ch395_close_socket_snunsigned-char-socketid","title":"oid ch395_close_socket_sn(unsigned char socketid)","text":"Description
Close socket
Input
"},{"location":"2024.1/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"Description
Get dhcp status
"},{"location":"2024.1/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"Description
Get General interrupt Status
"},{"location":"2024.1/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"Description
Get ch395 firmware version
"},{"location":"2024.1/c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"Description
Check interrupt socket status
Input
"},{"location":"2024.1/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"Description
Get ip info
"},{"location":"2024.1/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"Description
Get mac address
"},{"location":"2024.1/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"Description
Get physical status
"},{"location":"2024.1/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"Description
Get the length received from socket
Input
"},{"location":"2024.1/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"Description
Get remote ip connected to the socket
Input
"},{"location":"2024.1/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"Description
Returns in A socket status (close/open ... )
Input
"},{"location":"2024.1/c/#void-ch395_init","title":"void ch395_init();","text":"Description
Initialize ch395
"},{"location":"2024.1/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Input
"},{"location":"2024.1/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"Description
Reset ch395
"},{"location":"2024.1/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"Description
Retran period
"},{"location":"2024.1/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"Description
Set dest port socket
Input
"},{"location":"2024.1/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"Description
Set fun para
Description
Set gateway ip addr
Description
Set ip addr
"},{"location":"2024.1/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"Description
Set ipraw protocol on socket
Input
"},{"location":"2024.1/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.1/c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"Description
Set retran period
"},{"location":"2024.1/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"Description
Set source socket
Input
"},{"location":"2024.1/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Description
Send data to socketid
Input
"},{"location":"2024.2/assembly/","title":"Assembly","text":""},{"location":"2024.2/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.2/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"Description
This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
Modify
Returns
Example
jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
"},{"location":"2024.2/assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
Input
Modify
Example
lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
"},{"location":"2024.2/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
Modify
Example
lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
"},{"location":"2024.2/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Input
Modify
Description
This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.
Does not work
"},{"location":"2024.2/assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"Description
This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:
Example
jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n
Modify
Description
Get dhcp status
Example
jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n
Modify
Description
This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Does not work
"},{"location":"2024.2/assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"Description
This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Bit Name Description
7 GINT_STAT_SOCK3 Socket3 interrupt
6 GINT_STAT_SOCK2 Socket2 interrupt
5 GINT_STAT_SOCK1 Socket1 interrupt
4 GINT_STAT_SOCK0 Socket0 interrupt
3 GINT_STAT_DHCP DHCP interrupt
2 GINT_STAT_PHY_CHANGE PHY status change interrupt
1 GINT_STAT_IP_CONFLI IP conflict
0 GINT_STAT_UNREACH Inaccessible interrupt
\u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt
message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible
information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the
command GET_UNREACH_IPPORT to get the inaccessible information.
\u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its
IP address is the same as that of other network devices in the same network segment.
\u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection
of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or
from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get
the current PHY connection status.
\u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate
this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the
status is 0, it will indicate success; otherwise, it will indicate timeout failure.
\u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in
Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the
interrupt status of Socket. Please refer to GET_INT_STATUS_SN.
When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt
status
Modify
Returns
Example
jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
"},{"location":"2024.2/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"Description
This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
Modify
Returns
Example
jsr ch395_get_ic_ver\n; Check A for version\nrts\n
"},{"location":"2024.2/assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"Description
This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index
Input
Modify
Returns
Example
lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
"},{"location":"2024.2/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"Description
Get ip info
Input
Modify
Description
Get mac address
Input
Modify
Returns
Accumulator : the content of ptr modified
X Register : the content of ptr modified
Description
This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H
Modify
Returns
Example
jsr ch395_get_phy_status\n; Check A physical status\nrts\n
"},{"location":"2024.2/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"Description
Get the length received from socket
Input
Example
lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n
Modify
Returns
Accumulator : The length
X Register : The length
Description
This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command
Input
Modify
Example
lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
"},{"location":"2024.2/assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"Description
This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:
Input
Modify
Returns
Accumulator : The status
X Register : The state
Example
lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
"},{"location":"2024.2/assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"Description
This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).
Does not work
"},{"location":"2024.2/assembly/#ch395_init","title":"ch395_init","text":"Description
This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.
Modify
Reset ch395
Example
jsr ch395_init\n; Wait a bit\n
"},{"location":"2024.2/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"Description
Open socket from arg
Input
Modify
Description
Get buffer from socket
Input
Modify
Description
This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.
Example
jsr ch395_reset_all\n; Wait a bit\n
"},{"location":"2024.2/assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"Description
This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.
"},{"location":"2024.2/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"Description
Set dest port socket
Input
Modify
Example
lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
"},{"location":"2024.2/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"Description
Set fun para
Input
Modify
Description
This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address
Does not work
"},{"location":"2024.2/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"Description
This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below
Does not work
"},{"location":"2024.2/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"Description
Set Socket Ip address to connect with
Input
Description
Set ipraw protocol on socket
Input
Modify
Description
This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address
Input
Modify
Does not work
"},{"location":"2024.2/assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"Description
This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set
Does not work
"},{"location":"2024.2/assembly/#ch395_set_phy","title":"ch395_set_phy","text":"Description
This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.
Does not work
"},{"location":"2024.2/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"Input
Description
This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.
Input
Description
This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.
Input
Modify
Example
lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
"},{"location":"2024.2/assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"Description
Set source port
Input
Modify
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
Input
Input
Input
Description
TCP listen socket
"},{"location":"2024.2/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"Description
Send data to socketid
Input
Modify
Description
Checks if ch395 exists
"},{"location":"2024.2/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
"},{"location":"2024.2/c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
"},{"location":"2024.2/c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Description
Get cmd status
"},{"location":"2024.2/c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"2024.2/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"Description
Get dhcp status
"},{"location":"2024.2/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"Description
Get General interrupt Status
"},{"location":"2024.2/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"Description
Get ch395 firmware version
"},{"location":"2024.2/c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"Description
Check interrupt socket status
Input
"},{"location":"2024.2/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"Description
Get ip info
"},{"location":"2024.2/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"Description
Get mac address
"},{"location":"2024.2/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"Description
Get physical status
"},{"location":"2024.2/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"Description
Get the length received from socket
Input
"},{"location":"2024.2/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"Description
Get remote ip connected to the socket
Input
"},{"location":"2024.2/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"Description
Returns in A socket status (close/open ... )
Input
"},{"location":"2024.2/c/#void-ch395_init","title":"void ch395_init();","text":"Description
Initialize ch395
"},{"location":"2024.2/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"Input
"},{"location":"2024.2/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"Description
Reset ch395
"},{"location":"2024.2/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"Description
Set dest port socket
Input
"},{"location":"2024.2/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"Description
Set fun para
Description
Set gateway ip addr
Description
Set ip addr
"},{"location":"2024.2/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"Description
Set ipraw protocol on socket
Input
"},{"location":"2024.2/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.2/c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"Description
Set retran period
"},{"location":"2024.2/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"Description
Retran period
"},{"location":"2024.2/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"Description
Set source socket
Input
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
"},{"location":"2024.2/c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"2024.2/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Description
Send data to socketid [Not working]
Input
"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Introduction","text":"This lib is used to manage ch395 chip for 6502 cpu
"},{"location":"assembly/","title":"Assembly","text":""},{"location":"assembly/#assembly","title":"Assembly","text":""},{"location":"assembly/#ch395_check_exist","title":"ch395_check_exist","text":"Description
This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
Modify
Returns
Example
jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
"},{"location":"assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
Input
Modify
Example
lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
"},{"location":"assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
Modify
Example
lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
"},{"location":"assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Input
Modify
Description
This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.
Does not work
"},{"location":"assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"Description
This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:
Example
jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n
Modify
Description
Get dhcp status
Example
jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n
Modify
Description
This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Does not work
"},{"location":"assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"Description
This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Bit Name Description
7 GINT_STAT_SOCK3 Socket3 interrupt
6 GINT_STAT_SOCK2 Socket2 interrupt
5 GINT_STAT_SOCK1 Socket1 interrupt
4 GINT_STAT_SOCK0 Socket0 interrupt
3 GINT_STAT_DHCP DHCP interrupt
2 GINT_STAT_PHY_CHANGE PHY status change interrupt
1 GINT_STAT_IP_CONFLI IP conflict
0 GINT_STAT_UNREACH Inaccessible interrupt
\u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt
message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible
information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the
command GET_UNREACH_IPPORT to get the inaccessible information.
\u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its
IP address is the same as that of other network devices in the same network segment.
\u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection
of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or
from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get
the current PHY connection status.
\u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate
this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the
status is 0, it will indicate success; otherwise, it will indicate timeout failure.
\u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in
Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the
interrupt status of Socket. Please refer to GET_INT_STATUS_SN.
When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt
status
Modify
Returns
Example
jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
"},{"location":"assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"Description
This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
Modify
Returns
Example
jsr ch395_get_ic_ver\n; Check A for version\nrts\n
"},{"location":"assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"Description
This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:
Input
Modify
Returns
Example
lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
"},{"location":"assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"Description
Get ip info
Input
Modify
Description
Get mac address
Input
Modify
Returns
Accumulator : the content of ptr modified
X Register : the content of ptr modified
Description
This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H
Modify
Returns
Example
jsr ch395_get_phy_status\n; Check A physical status\nrts\n
"},{"location":"assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"Description
Get the length received from socket
Input
Example
lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n
Modify
Returns
Accumulator : The length
X Register : The length
Description
This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command
Input
Modify
Example
lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
"},{"location":"assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"Description
This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:
Input
Modify
Returns
Accumulator : The status
X Register : The state
Example
lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
"},{"location":"assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"Description
This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).
Does not work
"},{"location":"assembly/#ch395_init","title":"ch395_init","text":"Description
This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.
Modify
Reset ch395
Example
jsr ch395_init\n; Wait a bit\n
"},{"location":"assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"Description
This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.
Input
Modify
Description
Get buffer from socket
Input
Modify
Description
This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.
Example
jsr ch395_reset_all\n; Wait a bit\n
"},{"location":"assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"Description
This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.
"},{"location":"assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"Description
This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.
Input
Modify
Example
lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
"},{"location":"assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"Description
Set fun para
Input
Modify
Description
This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address
Does not work
"},{"location":"assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"Description
This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below
Does not work
"},{"location":"assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"Description
This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
Input
Modify
"},{"location":"assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"Description
Set ipraw protocol on socket
Input
Modify
Description
This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address
Input
Modify
Does not work
"},{"location":"assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"Description
This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set
Does not work
"},{"location":"assembly/#ch395_set_phy","title":"ch395_set_phy","text":"Description
This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.
Does not work
"},{"location":"assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"Description
This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:
Code Name Description
03H PROTO_TYPE_TCP TCP mode
02H PROTO_TYPE_UDP UDP mode
01H PROTO_TYPE_MAC_RAW MAC original message mode
00H PROTO_TYPE_IP_RAW IP original message mode
This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference
Steps for detailed steps.
Input
Description
This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.
Input
Modify
Description
This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.
Input
Modify
Example
lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
"},{"location":"assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"Description
This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.
Input
Modify
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
Input
Modify
Input
Input
Description
This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.
"},{"location":"assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"Description
This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again
Input
Modify
Example
"},{"location":"c/","title":"C","text":""},{"location":"c/#c","title":"C","text":""},{"location":"c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"Description
This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
"},{"location":"c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
"},{"location":"c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
"},{"location":"c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Description
Get cmd status
"},{"location":"c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"Description
Get dhcp status
"},{"location":"c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"Description
Get General interrupt Status
"},{"location":"c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"Description
;;@brief This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
;;@inputA Socket id ;;@modifyA ;;@modifyX ;;@returnsA Status of selected socket ;;@ca65 ;;@` lda #CH395_SOCKET1 ; Check socket 1 ;;@` jsr ch395_get_int_status_sn ;;@` ; Check interrupt type ;;@` and #CH395_SINT_STAT_SEND_OK ;;@` cmp #CH395_SINT_STAT_SEND_OK ;;@` beq @send_ok ;;@` rts ;;@
ldx #CH395_GET_INT_STATUS_SN stx CH395_COMMAND_PORT sta CH395_DATA_PORT lda CH395_DATA_PORT rts endproc
Description
Check interrupt socket status
Input
"},{"location":"c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"Description
Get ip info
"},{"location":"c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"Description
Get mac address
"},{"location":"c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"Description
Get physical status
"},{"location":"c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"Description
Get the length received from socket
Input
"},{"location":"c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"Description
Get remote ip connected to the socket
Input
"},{"location":"c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"Description
Returns in A socket status (close/open ... )
Input
"},{"location":"c/#void-ch395_init","title":"void ch395_init();","text":"Description
Initialize ch395
"},{"location":"c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"Input
"},{"location":"c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"Description
Reset ch395
"},{"location":"c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"Description
Set dest port socket
Input
"},{"location":"c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"Description
Set fun para
Description
Set gateway ip addr
Description
This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
"},{"location":"c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"Description
Set ipraw protocol on socket
Input
"},{"location":"c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"Description
Set retran period
"},{"location":"c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"Description
Retran period
"},{"location":"c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"Description
Set source socket
Input
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
"},{"location":"c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Description
Send data to socketid [Not working]
Input
"},{"location":"2024.1/assembly/","title":"Assembly","text":""},{"location":"2024.1/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.1/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"Description
Checks if ch395 exists
Example
jsr ch395_get_glob_int_status\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
Modify
Returns
Description
Clear receive buffer
Input
Modify
Example
lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
"},{"location":"2024.1/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"Description
Close socket
Input
Modify
Example
lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
"},{"location":"2024.1/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"Description
Enable or not dhcp
Input
Modify
Description
Get cmd status
Example
jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n
Modify
Description
Get dhcp status
Example
jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n
Modify
Description
Get General interrupt Status
Modify
Example
jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
"},{"location":"2024.1/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"Description
Get ch395 firmware version
Example
jsr ch395_get_ic_ver\n; Check A for version\nrts\n
Modify
Description
Check interrupt socket status
Input
Modify
Returns
Example
lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nrts\n
"},{"location":"2024.1/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"Description
Get ip info
Input
Modify
Description
Get mac address
Input
Modify
Returns
Accumulator : the content of ptr modified
X Register : the content of ptr modified
Description
Get physical status
Modify
Returns
Example
jsr ch395_get_phy_status\n; Check A physical status\nrts\n
"},{"location":"2024.1/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"Description
Get the length received from socket
Input
Example
lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n
Modify
Returns
Accumulator : The length
X Register : The length
Description
Get remote ip connected to the socket
Input
Modify
Description
Returns in A socket status (close/open ...)
Input
Modify
Returns
Accumulator : The status
X Register : The state
Example
lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\n
"},{"location":"2024.1/assembly/#ch395_init","title":"ch395_init","text":"Description
Initialize ch395
Modify
Reset ch395
Example
jsr ch395_init\n; Wait a bit\n
"},{"location":"2024.1/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"Description
Open socket from arg
Input
Modify
Input
Description
Reset ch395
Example
jsr ch395_reset_all\n; Wait a bit\n
"},{"location":"2024.1/assembly/#ch395_retran_period","title":"ch395_retran_period","text":"Description
Retran period
Input
Modify
Example
lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
"},{"location":"2024.1/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"Description
Set dest port socket
Input
Example
lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
"},{"location":"2024.1/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"Description
Set fun para
Input
Modify
Description
Set gateway ip addr
"},{"location":"2024.1/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"Description
Set ip row
"},{"location":"2024.1/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"Description
Set Socket Ip address to connect with
Input
Description
Set ipraw protocol on socket
Input
Description
Set mac address
"},{"location":"2024.1/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"Input
Description
Set retran period
Input
Input
Input
Input
Description
TCP listen socket
"},{"location":"2024.1/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"Description
Send data to socketid
Input
Description
Checks if ch395 exists
"},{"location":"2024.1/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"Description
Clear receive buffer
"},{"location":"2024.1/c/#oid-ch395_close_socket_snunsigned-char-socketid","title":"oid ch395_close_socket_sn(unsigned char socketid)","text":"Description
Close socket
Input
"},{"location":"2024.1/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"Description
Get dhcp status
"},{"location":"2024.1/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"Description
Get General interrupt Status
"},{"location":"2024.1/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"Description
Get ch395 firmware version
"},{"location":"2024.1/c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"Description
Check interrupt socket status
Input
"},{"location":"2024.1/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"Description
Get ip info
"},{"location":"2024.1/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"Description
Get mac address
"},{"location":"2024.1/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"Description
Get physical status
"},{"location":"2024.1/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"Description
Get the length received from socket
Input
"},{"location":"2024.1/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"Description
Get remote ip connected to the socket
Input
"},{"location":"2024.1/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"Description
Returns in A socket status (close/open ... )
Input
"},{"location":"2024.1/c/#void-ch395_init","title":"void ch395_init();","text":"Description
Initialize ch395
"},{"location":"2024.1/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Input
"},{"location":"2024.1/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"Description
Reset ch395
"},{"location":"2024.1/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"Description
Retran period
"},{"location":"2024.1/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"Description
Set dest port socket
Input
"},{"location":"2024.1/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"Description
Set fun para
Description
Set gateway ip addr
Description
Set ip addr
"},{"location":"2024.1/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"Description
Set ipraw protocol on socket
Input
"},{"location":"2024.1/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.1/c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"Description
Set retran period
"},{"location":"2024.1/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"Description
Set source socket
Input
"},{"location":"2024.1/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.1/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Description
Send data to socketid
Input
"},{"location":"2024.2/assembly/","title":"Assembly","text":""},{"location":"2024.2/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.2/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"Description
This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
Modify
Returns
Example
jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
"},{"location":"2024.2/assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
Input
Modify
Example
lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
"},{"location":"2024.2/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
Modify
Example
lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
"},{"location":"2024.2/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Input
Modify
Description
This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.
Does not work
"},{"location":"2024.2/assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"Description
This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:
Example
jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n
Modify
Description
Get dhcp status
Example
jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n
Modify
Description
This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Does not work
"},{"location":"2024.2/assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"Description
This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:
Bit Name Description
7 GINT_STAT_SOCK3 Socket3 interrupt
6 GINT_STAT_SOCK2 Socket2 interrupt
5 GINT_STAT_SOCK1 Socket1 interrupt
4 GINT_STAT_SOCK0 Socket0 interrupt
3 GINT_STAT_DHCP DHCP interrupt
2 GINT_STAT_PHY_CHANGE PHY status change interrupt
1 GINT_STAT_IP_CONFLI IP conflict
0 GINT_STAT_UNREACH Inaccessible interrupt
\u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt
message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible
information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the
command GET_UNREACH_IPPORT to get the inaccessible information.
\u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its
IP address is the same as that of other network devices in the same network segment.
\u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection
of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or
from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get
the current PHY connection status.
\u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate
this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the
status is 0, it will indicate success; otherwise, it will indicate timeout failure.
\u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in
Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the
interrupt status of Socket. Please refer to GET_INT_STATUS_SN.
When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt
status
Modify
Returns
Example
jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
"},{"location":"2024.2/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"Description
This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
Modify
Returns
Example
jsr ch395_get_ic_ver\n; Check A for version\nrts\n
"},{"location":"2024.2/assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"Description
This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:
Input
Modify
Returns
Example
lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
"},{"location":"2024.2/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"Description
Get ip info
Input
Modify
Description
Get mac address
Input
Modify
Returns
Accumulator : the content of ptr modified
X Register : the content of ptr modified
Description
This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H
Modify
Returns
Example
jsr ch395_get_phy_status\n; Check A physical status\nrts\n
"},{"location":"2024.2/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"Description
Get the length received from socket
Input
Example
lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n
Modify
Returns
Accumulator : The length
X Register : The length
Description
This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command
Input
Modify
Example
lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
"},{"location":"2024.2/assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"Description
This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:
Input
Modify
Returns
Accumulator : The status
X Register : The state
Example
lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
"},{"location":"2024.2/assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"Description
This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).
Does not work
"},{"location":"2024.2/assembly/#ch395_init","title":"ch395_init","text":"Description
This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.
Modify
Reset ch395
Example
jsr ch395_init\n; Wait a bit\n
"},{"location":"2024.2/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"Description
This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.
Input
Modify
Description
Get buffer from socket
Input
Modify
Description
This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.
Example
jsr ch395_reset_all\n; Wait a bit\n
"},{"location":"2024.2/assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"Description
This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.
"},{"location":"2024.2/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"Description
This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.
Input
Modify
Example
lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
"},{"location":"2024.2/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"Description
Set fun para
Input
Modify
Description
This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address
Does not work
"},{"location":"2024.2/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"Description
This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below
Does not work
"},{"location":"2024.2/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"Description
This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
Input
Modify
"},{"location":"2024.2/assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"Description
Set ipraw protocol on socket
Input
Modify
Description
This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address
Input
Modify
Does not work
"},{"location":"2024.2/assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"Description
This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set
Does not work
"},{"location":"2024.2/assembly/#ch395_set_phy","title":"ch395_set_phy","text":"Description
This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.
Does not work
"},{"location":"2024.2/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"Description
This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:
Code Name Description
03H PROTO_TYPE_TCP TCP mode
02H PROTO_TYPE_UDP UDP mode
01H PROTO_TYPE_MAC_RAW MAC original message mode
00H PROTO_TYPE_IP_RAW IP original message mode
This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference
Steps for detailed steps.
Input
Description
This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.
Input
Modify
Description
This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.
Input
Modify
Example
lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
"},{"location":"2024.2/assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"Description
This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.
Input
Modify
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
Input
Modify
Input
Input
Description
This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.
"},{"location":"2024.2/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"Description
This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again
Input
Modify
Example
"},{"location":"2024.2/c/","title":"C","text":""},{"location":"2024.2/c/#c","title":"C","text":""},{"location":"2024.2/c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"Description
This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.
"},{"location":"2024.2/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"Description
This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.
"},{"location":"2024.2/c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"Description
This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.
Input
"},{"location":"2024.2/c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"Description
This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status
Description
Get cmd status
"},{"location":"2024.2/c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"2024.2/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"Description
Get dhcp status
"},{"location":"2024.2/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"Description
Get General interrupt Status
"},{"location":"2024.2/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"Description
;;@brief This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text
;;@inputA Socket id ;;@modifyA ;;@modifyX ;;@returnsA Status of selected socket ;;@ca65 ;;@` lda #CH395_SOCKET1 ; Check socket 1 ;;@` jsr ch395_get_int_status_sn ;;@` ; Check interrupt type ;;@` and #CH395_SINT_STAT_SEND_OK ;;@` cmp #CH395_SINT_STAT_SEND_OK ;;@` beq @send_ok ;;@` rts ;;@
ldx #CH395_GET_INT_STATUS_SN stx CH395_COMMAND_PORT sta CH395_DATA_PORT lda CH395_DATA_PORT rts endproc
Description
Check interrupt socket status
Input
"},{"location":"2024.2/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"Description
Get ip info
"},{"location":"2024.2/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"Description
Get mac address
"},{"location":"2024.2/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"Description
Get physical status
"},{"location":"2024.2/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"Description
Get the length received from socket
Input
"},{"location":"2024.2/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"Description
Get remote ip connected to the socket
Input
"},{"location":"2024.2/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"Description
Returns in A socket status (close/open ... )
Input
"},{"location":"2024.2/c/#void-ch395_init","title":"void ch395_init();","text":"Description
Initialize ch395
"},{"location":"2024.2/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"Input
"},{"location":"2024.2/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"Description
Reset ch395
"},{"location":"2024.2/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"Description
Set dest port socket
Input
"},{"location":"2024.2/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"Description
Set fun para
Description
Set gateway ip addr
Description
This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent
"},{"location":"2024.2/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"Description
Set ipraw protocol on socket
Input
"},{"location":"2024.2/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.2/c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"Description
Set retran period
"},{"location":"2024.2/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"Description
Retran period
"},{"location":"2024.2/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"Description
Set source socket
Input
Description
This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128
"},{"location":"2024.2/c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"2024.2/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"Input
"},{"location":"2024.2/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"Description
Send data to socketid [Not working]
Input
"}]} \ No newline at end of file diff --git a/docs/api/sitemap.xml.gz b/docs/api/sitemap.xml.gz index 53bd0de..b610fac 100644 Binary files a/docs/api/sitemap.xml.gz and b/docs/api/sitemap.xml.gz differ diff --git a/docs/api/stylesheets/extra.css b/docs/api/stylesheets/extra.css index e7011b4..3e3d4d4 100644 --- a/docs/api/stylesheets/extra.css +++ b/docs/api/stylesheets/extra.css @@ -47,13 +47,9 @@ text-align: left; } -.md-typeset hr { - display: block; - height: 51px; - border: 0; - border-bottom: 1px solid #ADF; - margin: 1em 0; - padding: 0; +hr { + display: flow-root; + margin: 1.5em 0; + border-bottom: px2rem(1px) solid var(--md-default-fg-color--lightest); } - diff --git a/docs/builddocs.sh b/docs/builddocs.sh index 0ff8429..25162c1 100644 --- a/docs/builddocs.sh +++ b/docs/builddocs.sh @@ -17,6 +17,8 @@ echo "" >> docs/code/$VERSION/c.md echo $VERSION +cat src/include/ch395.inc | python3 docs/ca65todoc.py >> docs/code/$VERSION/assembly.md + for I in `ls src/6502/*.s`; do echo $I cat $I | python3 docs/ca65todoc.py >> docs/code/$VERSION/assembly.md diff --git a/docs/code/2024.2/assembly.md b/docs/code/2024.2/assembly.md index aa0dd36..842c343 100644 --- a/docs/code/2024.2/assembly.md +++ b/docs/code/2024.2/assembly.md @@ -281,7 +281,7 @@ This command is used to get the chip and firmware versions. 1 byte of data retur ***Description*** -This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index +This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows: ***Input*** @@ -537,7 +537,7 @@ Reset ch395 ***Description*** -Open socket from arg +This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps. ***Input*** @@ -602,7 +602,7 @@ This command is used to set the baud rate of CH395 for serial communication. Whe ***Description*** -Set dest port socket +This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set. ***Input*** @@ -672,11 +672,17 @@ This command is used to set IP address for CH395. It is necessary to input 4 byt ***Description*** -Set Socket Ip address to connect with +This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent ***Input*** * Accumulator : Socket id +* Y Register : low ptr ip +* X Register : high ptr ip + +***Modify*** + + --- @@ -750,6 +756,24 @@ This command is used to set Ethernet PHY connection mode of CH395. The connectio ## ch395_set_proto_type_sn +***Description*** + +This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows: + +Code Name Description + +03H PROTO_TYPE_TCP TCP mode + +02H PROTO_TYPE_UDP UDP mode + +01H PROTO_TYPE_MAC_RAW MAC original message mode + +00H PROTO_TYPE_IP_RAW IP original message mode + +This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference + +Steps for detailed steps. + ***Input*** * Accumulator : Socket id @@ -767,6 +791,10 @@ This command is used to set the number of retries. It is necessary to input 1 by * Accumulator : Retran period +***Modify*** + +* X Register + --- @@ -802,7 +830,7 @@ This command is used to set the retry cycle. It is necessary to input 2 bytes of ***Description*** -Set source port +This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure. ***Input*** @@ -828,6 +856,10 @@ This command is used to set Socket TTL. It is necessary to input 1 byte of Socke * Accumulator : Socket ID * X Register : TTL value +***Modify*** + +* Y Register + --- @@ -853,7 +885,7 @@ This command is used to set Socket TTL. It is necessary to input 1 byte of Socke ***Description*** -TCP listen socket +This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected. @@ -863,7 +895,7 @@ TCP listen socket ***Description*** -Send data to socketid +This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again ***Input*** @@ -876,4 +908,10 @@ Send data to socketid * RESTmp +***Example*** + +```ca65 +``` + + diff --git a/docs/code/2024.2/c.md b/docs/code/2024.2/c.md index b55c6a6..b775bb4 100644 --- a/docs/code/2024.2/c.md +++ b/docs/code/2024.2/c.md @@ -4,7 +4,7 @@ ***Description*** -Checks if ch395 exists +This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H. @@ -63,10 +63,29 @@ Get General interrupt Status ***Description*** -Get ch395 firmware version - - - +;;@brief This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text + + + + ;;@inputA Socket id + ;;@modifyA + ;;@modifyX + ;;@returnsA Status of selected socket + ;;@```ca65 + ;;@` lda #CH395_SOCKET1 ; Check socket 1 + ;;@` jsr ch395_get_int_status_sn + ;;@` ; Check interrupt type + ;;@` and #CH395_SINT_STAT_SEND_OK + ;;@` cmp #CH395_SINT_STAT_SEND_OK + ;;@` beq @send_ok + ;;@` rts + ;;@``` +ldx #CH395_GET_INT_STATUS_SN + stx CH395_COMMAND_PORT + sta CH395_DATA_PORT + lda CH395_DATA_PORT + rts +endproc ## unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET); ***Description*** @@ -192,7 +211,7 @@ Set gateway ip addr ***Description*** -Set ip addr +This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent diff --git a/docs/code/assembly.md b/docs/code/assembly.md index aa0dd36..842c343 100644 --- a/docs/code/assembly.md +++ b/docs/code/assembly.md @@ -281,7 +281,7 @@ This command is used to get the chip and firmware versions. 1 byte of data retur ***Description*** -This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index +This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows: ***Input*** @@ -537,7 +537,7 @@ Reset ch395 ***Description*** -Open socket from arg +This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps. ***Input*** @@ -602,7 +602,7 @@ This command is used to set the baud rate of CH395 for serial communication. Whe ***Description*** -Set dest port socket +This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set. ***Input*** @@ -672,11 +672,17 @@ This command is used to set IP address for CH395. It is necessary to input 4 byt ***Description*** -Set Socket Ip address to connect with +This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent ***Input*** * Accumulator : Socket id +* Y Register : low ptr ip +* X Register : high ptr ip + +***Modify*** + + --- @@ -750,6 +756,24 @@ This command is used to set Ethernet PHY connection mode of CH395. The connectio ## ch395_set_proto_type_sn +***Description*** + +This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows: + +Code Name Description + +03H PROTO_TYPE_TCP TCP mode + +02H PROTO_TYPE_UDP UDP mode + +01H PROTO_TYPE_MAC_RAW MAC original message mode + +00H PROTO_TYPE_IP_RAW IP original message mode + +This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference + +Steps for detailed steps. + ***Input*** * Accumulator : Socket id @@ -767,6 +791,10 @@ This command is used to set the number of retries. It is necessary to input 1 by * Accumulator : Retran period +***Modify*** + +* X Register + --- @@ -802,7 +830,7 @@ This command is used to set the retry cycle. It is necessary to input 2 bytes of ***Description*** -Set source port +This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure. ***Input*** @@ -828,6 +856,10 @@ This command is used to set Socket TTL. It is necessary to input 1 byte of Socke * Accumulator : Socket ID * X Register : TTL value +***Modify*** + +* Y Register + --- @@ -853,7 +885,7 @@ This command is used to set Socket TTL. It is necessary to input 1 byte of Socke ***Description*** -TCP listen socket +This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected. @@ -863,7 +895,7 @@ TCP listen socket ***Description*** -Send data to socketid +This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again ***Input*** @@ -876,4 +908,10 @@ Send data to socketid * RESTmp +***Example*** + +```ca65 +``` + + diff --git a/docs/code/c.md b/docs/code/c.md index b55c6a6..b775bb4 100644 --- a/docs/code/c.md +++ b/docs/code/c.md @@ -4,7 +4,7 @@ ***Description*** -Checks if ch395 exists +This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H. @@ -63,10 +63,29 @@ Get General interrupt Status ***Description*** -Get ch395 firmware version - - - +;;@brief This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text + + + + ;;@inputA Socket id + ;;@modifyA + ;;@modifyX + ;;@returnsA Status of selected socket + ;;@```ca65 + ;;@` lda #CH395_SOCKET1 ; Check socket 1 + ;;@` jsr ch395_get_int_status_sn + ;;@` ; Check interrupt type + ;;@` and #CH395_SINT_STAT_SEND_OK + ;;@` cmp #CH395_SINT_STAT_SEND_OK + ;;@` beq @send_ok + ;;@` rts + ;;@``` +ldx #CH395_GET_INT_STATUS_SN + stx CH395_COMMAND_PORT + sta CH395_DATA_PORT + lda CH395_DATA_PORT + rts +endproc ## unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET); ***Description*** @@ -192,7 +211,7 @@ Set gateway ip addr ***Description*** -Set ip addr +This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent diff --git a/src/6502/_ch395_check_exist.s b/src/6502/_ch395_check_exist.s index 539a331..89269d7 100644 --- a/src/6502/_ch395_check_exist.s +++ b/src/6502/_ch395_check_exist.s @@ -5,7 +5,7 @@ .proc _ch395_check_exist ;;@proto unsigned char ch395_check_exist(); - ;;@brief Checks if ch395 exists + ;;@brief This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H. ;;@```c ;;@` val = ch395_check_exist(); ;;@` if (val == CH395_DETECTED) printf("Ch395 is here"); diff --git a/src/6502/_ch395_get_ic_ver.s b/src/6502/_ch395_get_ic_ver.s index 78794ec..2855e28 100644 --- a/src/6502/_ch395_get_ic_ver.s +++ b/src/6502/_ch395_get_ic_ver.s @@ -5,7 +5,7 @@ .proc _ch395_get_ic_ver ;;@proto unsigned char ch395_get_ic_ver(); - ;;@brief Get ch395 firmware version + ;;@brief ;;@brief This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text ;;@```c ;;@` unsigned char val; ;;@` val = ch395_get_ic_ver(); diff --git a/src/6502/_ch395_init.s b/src/6502/_ch395_init.s index 7ab1e9c..76f159f 100644 --- a/src/6502/_ch395_init.s +++ b/src/6502/_ch395_init.s @@ -5,7 +5,7 @@ .proc _ch395_init ;;@proto void ch395_init(); - ;;@brief Initialize ch395 + ;;@brief ;;@brief This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status. jmp ch395_init .endproc diff --git a/src/6502/_ch395_set_ip_addr.s b/src/6502/_ch395_set_ip_addr.s index 34829ce..0258a5b 100644 --- a/src/6502/_ch395_set_ip_addr.s +++ b/src/6502/_ch395_set_ip_addr.s @@ -6,6 +6,6 @@ .import popax .proc _ch395_set_ip_addr - ;;@brief Set ip addr + ;;@brief This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent jmp ch395_set_ip_addr .endproc diff --git a/src/6502/ch395_open_socket_sn.s b/src/6502/ch395_open_socket_sn.s index 9cd1f36..e6e8531 100644 --- a/src/6502/ch395_open_socket_sn.s +++ b/src/6502/ch395_open_socket_sn.s @@ -3,7 +3,7 @@ .export ch395_open_socket_sn .proc ch395_open_socket_sn - ;;@brief Open socket from arg + ;;@brief This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps. ;;@inputA Socket id ;;@modifyY ldy #CH395_OPEN_SOCKET_SN diff --git a/src/6502/ch395_set_des_port_sn.s b/src/6502/ch395_set_des_port_sn.s index ea0a4cb..d761ea2 100644 --- a/src/6502/ch395_set_des_port_sn.s +++ b/src/6502/ch395_set_des_port_sn.s @@ -4,7 +4,7 @@ .export ch395_set_des_port_sn .proc ch395_set_des_port_sn - ;;@brief Set dest port socket + ;;@brief This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set. ;;@inputA Socketid ;;@inputY Low int ;;@inputX high int diff --git a/src/6502/ch395_set_ip_addr_sn.s b/src/6502/ch395_set_ip_addr_sn.s index 95a5ce7..9f891ef 100644 --- a/src/6502/ch395_set_ip_addr_sn.s +++ b/src/6502/ch395_set_ip_addr_sn.s @@ -5,8 +5,11 @@ .export ch395_set_ip_addr_sn .proc ch395_set_ip_addr_sn - ;;@brief Set Socket Ip address to connect with + ;;@brief This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent ;;@inputA Socket id + ;;@inputY low ptr ip + ;;@inputX high ptr ip + ;;@modifyMEM8RES tmp sty RES stx RES+1 diff --git a/src/6502/ch395_set_proto_type_sn.s b/src/6502/ch395_set_proto_type_sn.s index 3a69334..f4b776c 100644 --- a/src/6502/ch395_set_proto_type_sn.s +++ b/src/6502/ch395_set_proto_type_sn.s @@ -3,6 +3,14 @@ .export ch395_set_proto_type_sn .proc ch395_set_proto_type_sn + ;;@brief This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows: + ;;@explain Code Name Description + ;;@explain 03H PROTO_TYPE_TCP TCP mode + ;;@explain 02H PROTO_TYPE_UDP UDP mode + ;;@explain 01H PROTO_TYPE_MAC_RAW MAC original message mode + ;;@explain 00H PROTO_TYPE_IP_RAW IP original message mode + ;;@explain This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference + ;;@explain Steps for detailed steps. ;;@inputA Socket id ldy #CH395_SET_PROTO_TYPE_SN sty CH395_COMMAND_PORT diff --git a/src/6502/ch395_set_retran_count.s b/src/6502/ch395_set_retran_count.s index a4e7ac9..a836cc1 100644 --- a/src/6502/ch395_set_retran_count.s +++ b/src/6502/ch395_set_retran_count.s @@ -5,6 +5,7 @@ .proc ch395_set_retran_count ;;@brief This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode. ;;@inputA Retran period + ;;@modifyX ldx #CH395_SET_RETRAN_COUNT stx CH395_COMMAND_PORT sta CH395_DATA_PORT diff --git a/src/6502/ch395_set_sour_port_sn.s b/src/6502/ch395_set_sour_port_sn.s index 213f6ef..883b9fc 100644 --- a/src/6502/ch395_set_sour_port_sn.s +++ b/src/6502/ch395_set_sour_port_sn.s @@ -4,7 +4,7 @@ .export ch395_set_sour_port_sn .proc ch395_set_sour_port_sn - ;;@brief Set source port + ;;@brief This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure. ;;@inputA Socket id ;;@inputY Low ptr address ;;@inputX High ptr address diff --git a/src/6502/ch395_set_ttl.s b/src/6502/ch395_set_ttl.s index c049be0..49e8864 100644 --- a/src/6502/ch395_set_ttl.s +++ b/src/6502/ch395_set_ttl.s @@ -6,6 +6,7 @@ ;;@brief This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128 ;;@inputA Socket ID ;;@inputX TTL value + ;;@modifyY ldy #CH395_SET_TTL sty CH395_COMMAND_PORT sta CH395_DATA_PORT ; Send socket id diff --git a/src/6502/ch395_tcp_listen_sn.s b/src/6502/ch395_tcp_listen_sn.s index eaf1c99..57cf5b7 100644 --- a/src/6502/ch395_tcp_listen_sn.s +++ b/src/6502/ch395_tcp_listen_sn.s @@ -3,7 +3,7 @@ .export ch395_tcp_listen_sn .proc ch395_tcp_listen_sn - ;;@brief TCP listen socket + ;;@brief This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected. ;;inputA SocketID ;;modifyY ldy #CH395_TCP_LISTEN_SN diff --git a/src/6502/ch395_write_send_buf_sn.s b/src/6502/ch395_write_send_buf_sn.s index 9a0c61c..3f426f2 100644 --- a/src/6502/ch395_write_send_buf_sn.s +++ b/src/6502/ch395_write_send_buf_sn.s @@ -4,41 +4,57 @@ .export ch395_write_send_buf_sn .proc ch395_write_send_buf_sn - ;;@brief Send data to socketid + ;;@brief This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again ;;@inputA Socket ID ;;@inputY Low length ;;@inputX High length ;;@inputMEM_RESB Adress ptr to read ;;@modifyMEM_RES Tmp - sty RES ; Length - stx RES+1 + ;;@```ca65 + ;;@sta RESB ; Ptr low to write + ;;@sty RESB+1 ; ptr high to write + ;;@ldy #<1000 ; Low length + ;;@ldx #>1000 ; High length + ;;@lda #$00 ; socket 0 + ;;@jsr ch395_write_send_buf_sn + ;;@rts + ;;@``` + + sty RESB ; Save low length + stx RESB+1 ; Save low length + + ; A contains Socket entry_point_c: ldy #CH395_WRITE_SEND_BUF_SN sty CH395_COMMAND_PORT - sta CH395_DATA_PORT + sta CH395_DATA_PORT ; Store socket value + + lda RESB + sta CH395_DATA_PORT ; set length low + stx CH395_DATA_PORT ; set length high - lda RES - ldx RES+1 - sta CH395_DATA_PORT ; set length - stx CH395_DATA_PORT ; set length + lda RESB + beq @decrement @restart: ldy #$00 @loop: - lda (RESB),y + lda (RES),y sta CH395_DATA_PORT iny - cpy RES + cpy RESB bne @loop -@exit: - rts - lda RES+1 +@decrement: + lda RESB+1 beq @exit - dec RES+1 - jmp @exit + lda #$FF + sta RESB + bne @restart + +@exit: rts .endproc diff --git a/test/ch395.c b/test/ch395.c new file mode 100644 index 0000000..19a216c --- /dev/null +++ b/test/ch395.c @@ -0,0 +1,23 @@ +#include